Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve OCaml Compiler Manuals #2150

Merged
merged 7 commits into from
Apr 15, 2024
Merged
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
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/global/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ocamlorg_web/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
42 changes: 38 additions & 4 deletions src/ocamlorg_web/lib/redirection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/**";
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/ocamlorg_web/lib/router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "") ];
Expand Down
Loading