diff --git a/Dockerfile b/Dockerfile index d9aa5bb1eb..1145765b00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,9 +34,12 @@ COPY --from=build /home/opam/_build/default/src/ocamlorg_web/bin/main.exe /bin/s COPY playground/asset playground/asset +RUN git clone https://github.com/ocaml-web/html-compiler-manuals /manual + RUN git config --global --add safe.directory /var/opam-repository ENV OCAMLORG_REPO_PATH /var/opam-repository/ +ENV OCAMLORG_MANUAL_PATH /manual ENV OCAMLORG_PKG_STATE_PATH /var/package.state ENV DREAM_VERBOSITY info ENV OCAMLORG_HTTP_PORT 8080 diff --git a/src/global/url.ml b/src/global/url.ml index 8e0fee4707..e44dface21 100644 --- a/src/global/url.ml +++ b/src/global/url.ml @@ -45,10 +45,10 @@ let minor v = | _ -> invalid_arg (v ^ ": invalid OCaml version") let v2 = "https://v2.ocaml.org" -let manual_with_version v = v2 ^ "/releases/" ^ minor v ^ "/htmlman/index.html" -let manual = "/releases/latest/manual.html" -let api_with_version v = v2 ^ "/releases/" ^ minor v ^ "/api/index.html" -let api = "/releases/latest/api/index.html" +let manual_with_version v = "/manual/" ^ minor v ^ "/index.html" +let manual = "/manual" +let api_with_version v = "/manual/" ^ minor v ^ "/api/index.html" +let api = "/api" let books = "/books" let changelog = "/changelog" let changelog_entry id = "/changelog/" ^ id diff --git a/src/ocamlorg_web/lib/config.ml b/src/ocamlorg_web/lib/config.ml index 37925cad41..d8ba90020d 100644 --- a/src/ocamlorg_web/lib/config.ml +++ b/src/ocamlorg_web/lib/config.ml @@ -4,3 +4,6 @@ let to_bool s = match String.lowercase_ascii s with "true" | "1" -> true | _ -> false let http_port = env_with_default "OCAMLORG_HTTP_PORT" "8080" |> int_of_string + +let manual_path = + env_with_default "OCAMLORG_MANUAL_PATH" "http-compiler-manuals" diff --git a/src/ocamlorg_web/lib/redirection.ml b/src/ocamlorg_web/lib/redirection.ml index e7b0c288dc..f8cbefe894 100644 --- a/src/ocamlorg_web/lib/redirection.ml +++ b/src/ocamlorg_web/lib/redirection.ml @@ -449,6 +449,43 @@ let from_v2 = ("/releases/latest/api/index.html", Url.api_with_version latest_version); ] +let default_index_html = + [ + ("/manual", Url.manual_with_version latest_version); + ("/manual/latest", Url.manual_with_version latest_version); + ("/api", Url.api_with_version latest_version); + ("/api/latest", Url.api_with_version latest_version); + ("/manual/api", Url.api_with_version latest_version); + ("/manual/api/latest", Url.api_with_version latest_version); + ("/manual/3.12", Url.manual_with_version "3.12"); + ("/manual/4.00", Url.manual_with_version "4.00"); + ("/manual/4.01", Url.manual_with_version "4.01"); + ("/manual/4.02", Url.manual_with_version "4.02"); + ("/manual/4.03", Url.manual_with_version "4.03"); + ("/manual/4.04", Url.manual_with_version "4.04"); + ("/manual/4.05", Url.manual_with_version "4.05"); + ("/manual/4.06", Url.manual_with_version "4.06"); + ("/manual/4.07", Url.manual_with_version "4.07"); + ("/manual/4.08", Url.manual_with_version "4.08"); + ("/manual/4.09", Url.manual_with_version "4.09"); + ("/manual/4.10", Url.manual_with_version "4.10"); + ("/manual/4.11", Url.manual_with_version "4.11"); + ("/manual/4.12", Url.manual_with_version "4.12"); + ("/manual/4.12/api", Url.api_with_version "4.12"); + ("/manual/4.13", Url.manual_with_version "4.13"); + ("/manual/4.13/api", Url.api_with_version "4.13"); + ("/manual/4.14", Url.manual_with_version "4.14"); + ("/manual/4.14/api", Url.api_with_version "4.14"); + ("/manual/5.0", Url.manual_with_version "5.0"); + ("/manual/5.0/api", Url.api_with_version "5.0"); + ("/manual/5.1", Url.manual_with_version "5.1"); + ("/manual/5.1/api", Url.api_with_version "5.1"); + ("/manual/5.2", Url.manual_with_version "5.2"); + ("/manual/5.2/api", Url.api_with_version "5.2"); + ("/manual/5.3", Url.manual_with_version "5.3"); + ("/manual/5.3/api", Url.api_with_version "5.3"); + ] + let redirect_p pattern = let handler req = let target = Dream.target req in @@ -461,10 +498,6 @@ let fwd_v2 origin = let manual = [ - redirect_p "/api/**"; - fwd_v2 "/api"; - redirect_p "/manual/**"; - fwd_v2 "/manual"; redirect_p "/releases/3.12/htmlman/**"; fwd_v2 "/releases/3.12/htmlman"; redirect_p "/releases/4.00/htmlman/**"; @@ -539,6 +572,7 @@ let package_docs req = let t = Dream.scope "" [] [ + make default_index_html; make from_v2; make v2_assets; Dream.scope "" [ Dream_encoding.compress ] manual; diff --git a/src/ocamlorg_web/lib/router.ml b/src/ocamlorg_web/lib/router.ml index d4dcef89b6..2a3061a454 100644 --- a/src/ocamlorg_web/lib/router.ml +++ b/src/ocamlorg_web/lib/router.ml @@ -120,6 +120,9 @@ let router t = package_route t; graphql_route t; sitemap_routes; + Dream.scope "" + [ Dream_encoding.compress ] + [ Dream.get "/manual/**" (Dream.static Config.manual_path) ]; Dream.scope "" [ Dream_encoding.compress ] [ Dream.get "/media/**" (Dream.static ~loader:media_loader "") ];