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 2 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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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 && for a in $(git -C /manual branch -r --format='%(refname:lstrip=3)') ; do git -C /manual submodule add ./ $a && git -C /manual/$a checkout $a; done
mtelvers marked this conversation as resolved.
Show resolved Hide resolved

RUN git config --global --add safe.directory /var/opam-repository

ENV OCAMLORG_REPO_PATH /var/opam-repository/
Expand Down
4 changes: 3 additions & 1 deletion src/global/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ let minor v =

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 manual = "/manual"
let manual_lang v = "/manual/" ^ minor v ^ "/index.html"
let manual_api v = "/manual/" ^ minor v ^ "/api/index.html"
mtelvers marked this conversation as resolved.
Show resolved Hide resolved
let api_with_version v = v2 ^ "/releases/" ^ minor v ^ "/api/index.html"
let api = "/releases/latest/api/index.html"
mtelvers marked this conversation as resolved.
Show resolved Hide resolved
let books = "/books"
Expand Down
25 changes: 23 additions & 2 deletions src/ocamlorg_web/lib/redirection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,25 @@ let from_v2 =
("/releases/latest/api/index.html", Url.api_with_version latest_version);
]

let default_index_html =
[
("/manual", Url.manual_lang latest_version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to add one for latest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a redirect for latest, we need to serve this via Dream under /manual/latest. A redirect would mean that the URL in the browser would change to the specific version.

("/manual/4.12", Url.manual_lang "4.12");
("/manual/4.12/api", Url.manual_api "4.12");
("/manual/4.13", Url.manual_lang "4.13");
("/manual/4.13/api", Url.manual_api "4.13");
("/manual/4.14", Url.manual_lang "4.14");
("/manual/4.14/api", Url.manual_api "4.14");
("/manual/5.0", Url.manual_lang "5.0");
("/manual/5.0/api", Url.manual_api "5.0");
("/manual/5.1", Url.manual_lang "5.1");
("/manual/5.1/api", Url.manual_api "5.1");
("/manual/5.2", Url.manual_lang "5.2");
("/manual/5.2/api", Url.manual_api "5.2");
("/manual/5.3", Url.manual_lang "5.3");
("/manual/5.3/api", Url.manual_api "5.3");
]

let redirect_p pattern =
let handler req =
let target = Dream.target req in
Expand All @@ -459,12 +478,13 @@ let redirect_p pattern =
let fwd_v2 origin =
Dream.get origin (fun req -> Dream.redirect req (Url.v2 ^ origin))

let serve url path = Dream.get url (Dream.static path)

let manual =
[
serve "/manual/**" "/manual/";
mtelvers marked this conversation as resolved.
Show resolved Hide resolved
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 +559,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
Loading