diff --git a/src/html/config.ml b/src/html/config.ml index c3d0825e25..a314efbcaf 100644 --- a/src/html/config.ml +++ b/src/html/config.ml @@ -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; diff --git a/src/html/link.ml b/src/html/link.ml index d63745b519..89314e03d2 100644 --- a/src/html/link.ml +++ b/src/html/link.ml @@ -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 = @@ -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 @@ -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 diff --git a/test/integration/remap.t/otherpage.mld b/test/integration/remap.t/otherpage.mld new file mode 100644 index 0000000000..a7a3c91c94 --- /dev/null +++ b/test/integration/remap.t/otherpage.mld @@ -0,0 +1,3 @@ +{0 Other Page} + +This is documentation from the other package. diff --git a/test/integration/remap.t/run.t b/test/integration/remap.t/run.t index e71214afe1..a7e919ea08 100644 --- a/test/integration/remap.t/run.t +++ b/test/integration/remap.t/run.t @@ -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: @@ -14,6 +16,12 @@ We should be able to remap the links to one of the packages: _html/prefix/mypkg/Test/index.html: Otherlib.t _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: otherpage + _html2/prefix/mypkg/Test/index.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/ diff --git a/test/integration/remap.t/test.mli b/test/integration/remap.t/test.mli index 202ccb07e5..914fd7a148 100644 --- a/test/integration/remap.t/test.mli +++ b/test/integration/remap.t/test.mli @@ -1,2 +1,4 @@ type t = Otherlib.t +(** See the {!page-otherpage} for more info. *) +