Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/html/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ type t = {
home_breadcrumb : string option;
}

let ensure_trailing_slash s =
if Astring.String.is_suffix ~affix:"/" s then s else s ^ "/"

let v ?(search_result = false) ?theme_uri ?support_uri ?(search_uris = [])
~semantic_uris ~indent ~flat ~open_details ~as_json ~remap ?home_breadcrumb
() =
let remap =
List.map
(fun (prefix, replacement) ->
(ensure_trailing_slash prefix, ensure_trailing_slash replacement))
remap
in
{
semantic_uris;
indent;
Expand Down
18 changes: 10 additions & 8 deletions src/html/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module Path = struct

let is_leaf_page url = url.Url.Path.kind = `LeafPage

let remap config f =
let l = String.concat "/" f in
let remap config dir file =
let path = String.concat "/" dir ^ "/" ^ file in
let remaps =
List.filter
(fun (prefix, _replacement) -> Astring.String.is_prefix ~affix:prefix l)
(fun (prefix, _) -> Astring.String.is_prefix ~affix:prefix path)
(Config.remap config)
in
let remaps =
Expand All @@ -26,9 +26,11 @@ module Path = struct
match remaps with
| [] -> None
| (prefix, replacement) :: _ ->
let len = String.length prefix in
let l = String.sub l len (String.length l - len) in
Some (replacement ^ l)
let remainder =
String.sub path (String.length prefix)
(String.length path - String.length prefix)
in
Some (replacement ^ remainder)

let get_dir_and_file ~config url =
let l = Url.Path.to_list url in
Expand All @@ -52,9 +54,9 @@ module Path = struct

let for_linking ~config url =
let dir, file = get_dir_and_file ~config url in
match remap config dir with
match remap config dir file with
| None -> Relative (dir, file)
| Some x -> Absolute (x ^ "/" ^ file)
| Some url -> Absolute url

let as_filename ~config (url : Url.Path.t) =
let dir, file = get_dir_and_file ~config url in
Expand Down
3 changes: 3 additions & 0 deletions test/integration/remap.t/otherpage.mld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{0 Other Page}

This is documentation from the other package.
8 changes: 8 additions & 0 deletions test/integration/remap.t/run.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
$ ocamlc -c -bin-annot otherlib.mli
$ ocamlc -c -bin-annot test.mli
$ odoc compile --parent-id prefix/otherpkg --output-dir _odoc otherlib.cmti
$ odoc compile --parent-id prefix/otherpkg --output-dir _odoc otherpage.mld
$ odoc compile --parent-id prefix/mypkg --output-dir _odoc test.cmti
$ odoc link _odoc/prefix/otherpkg/otherlib.odoc
$ odoc link _odoc/prefix/otherpkg/page-otherpage.odoc
$ odoc link -I _odoc/prefix/otherpkg _odoc/prefix/mypkg/test.odoc

We should be able to remap the links to one of the packages:
Expand All @@ -14,6 +16,12 @@ We should be able to remap the links to one of the packages:
_html/prefix/mypkg/Test/index.html: <a href="../../otherpkg/Otherlib/index.html#type-t">Otherlib.t</a>
_html2/prefix/mypkg/Test/index.html: href="https://mysite.org/p/otherpkg/1.2.3/Otherlib/index.html#type-t">

Page links should also be remapped:

$ grep otherpage.html _html/prefix/mypkg/Test/index.html _html2/prefix/mypkg/Test/index.html
_html/prefix/mypkg/Test/index.html: <a href="../../otherpkg/otherpage.html"><code>otherpage</code></a>
_html2/prefix/mypkg/Test/index.html: <a href="https://mysite.org/p/otherpkg/1.2.3/otherpage.html">

This shouldn't stop us from outputting the remapped package though, and the following should complete without error

$ odoc html-generate -o _html3 _odoc/prefix/otherpkg/otherlib.odocl -R prefix/otherpkg/:https://mysite.org/p/otherpkg/1.2.3/
Expand Down
2 changes: 2 additions & 0 deletions test/integration/remap.t/test.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
type t = Otherlib.t

(** See the {!page-otherpage} for more info. *)

Loading