File tree Expand file tree Collapse file tree 2 files changed +23
-11
lines changed
Expand file tree Collapse file tree 2 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -13,17 +13,22 @@ module Path = struct
1313
1414 let remap config f =
1515 let l = String. concat " /" f in
16- try
17- let prefix, replacement =
18- List. find
19- (fun (prefix , _replacement ) ->
20- Astring.String. is_prefix ~affix: prefix l)
21- (Config. remap config)
22- in
23- let len = String. length prefix in
24- let l = String. sub l len (String. length l - len) in
25- Some (replacement ^ l)
26- with Not_found -> None
16+ let remaps =
17+ List. filter
18+ (fun (prefix , _replacement ) -> Astring.String. is_prefix ~affix: prefix l)
19+ (Config. remap config)
20+ in
21+ let remaps =
22+ List. sort
23+ (fun (a , _ ) (b , _ ) -> compare (String. length b) (String. length a))
24+ remaps
25+ in
26+ match remaps with
27+ | [] -> None
28+ | (prefix , replacement ) :: _ ->
29+ let len = String. length prefix in
30+ let l = String. sub l len (String. length l - len) in
31+ Some (replacement ^ l)
2732
2833 let get_dir_and_file ~config url =
2934 let l = Url.Path. to_list url in
Original file line number Diff line number Diff line change @@ -18,3 +18,10 @@ This shouldn't stop us from outputting the remapped package though, and the foll
1818
1919 $ odoc html-generate -o _html3 _odoc/ prefix / otherpkg/ otherlib. odocl -R prefix / otherpkg/: https: // mysite. org/ p/ otherpkg/ 1.2 . 3/
2020
21+ The order shouldn't matter, the longest prefix ought to win
22+ $ odoc html-generate -o _html3 -- indent _odoc/ prefix / mypkg/ test. odocl -R prefix /: https: // mysite. org/ foo/ -R prefix / otherpkg/: https: // mysite. org/ bar/
23+ $ odoc html-generate -o _html4 -- indent _odoc/ prefix / mypkg/ test. odocl -R prefix / otherpkg/: https: // mysite. org/ bar/ -R prefix /: https: // mysite. org/ foo/
24+
25+ $ grep Otherlib/ index . html _html3/ prefix / mypkg/ Test / index . html _html4/ prefix / mypkg/ Test / index . html
26+ _html3/ prefix / mypkg/ Test / index . html: <a href="https://mysite.org/bar/Otherlib/index.html#type-t" >Otherlib. t
27+ _html4/ prefix / mypkg/ Test / index . html: <a href="https://mysite.org/bar/Otherlib/index.html#type-t" >Otherlib. t
You can’t perform that action at this time.
0 commit comments