Skip to content

Commit c36bc5f

Browse files
committed
Handle redirection
Since odoc 3, and the replacement of voodoo by odoc_driver as the odoc driver, the layout for docs has changed. Since we do not want to break previously existing links, we redirect the old layout to the new one.
1 parent 2debb4d commit c36bc5f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/ocamlorg_web/lib/handler.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,29 @@ let package_documentation t kind req =
12291229
in
12301230
let path = (Dream.path [@ocaml.warning "-3"]) req |> String.concat "/" in
12311231
let hash = match kind with `Package -> None | `Universe u -> Some u in
1232+
let url =
1233+
Url.Package.documentation ?hash ~page:path ~version:version_from_url
1234+
@@ Dream.param req "name"
1235+
in
1236+
let* package_documentation_status =
1237+
Ocamlorg_package.documentation_status ~kind t package
1238+
in
1239+
let redirect =
1240+
match package_documentation_status with
1241+
| None -> None
1242+
| Some { redirections; _ } ->
1243+
List.find_map
1244+
(function
1245+
| { Ocamlorg_package.Documentation_status.old_path; new_path } -> (
1246+
match String.cut ~on:old_path url with
1247+
| Some (prefix, "") -> Some (prefix ^ new_path)
1248+
| _ -> None))
1249+
redirections
1250+
in
1251+
let handle_redirect redirect continue =
1252+
match redirect with Some r -> Dream.redirect req r | None -> continue ()
1253+
in
1254+
handle_redirect redirect @@ fun () ->
12321255
let* docs = Ocamlorg_package.documentation_page ~kind package path in
12331256
match docs with
12341257
| None ->

0 commit comments

Comments
 (0)