Skip to content

Commit

Permalink
Merge pull request #547 from pfitaxel/dont-prefix-absolute-urls
Browse files Browse the repository at this point in the history
* Don't prefix URLs starting with `https?://` at `learn-ocaml build` time
Related: #535 and static deployment

* Move CSS code as a small cleanup
Related: #540
  • Loading branch information
erikmd committed May 1, 2023
2 parents 185328c + 84bc393 commit 1584a08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/main/learnocaml_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,18 @@ end
open Args

let process_html_file orig_file dest_file base_url no_secret =
let add_prefix_unless_http prefix url =
let https = "https://" and http = "http://" in
let starts_with proto =
String.(sub url 0 (min (length proto) (length url))) = proto in
if starts_with https || starts_with http then url
else prefix ^ url in
let transform_tag e tag attrs attr =
let attr_pair = ("", attr) in
match List.assoc_opt attr_pair attrs with
| Some url -> `Start_element ((e, tag), (attr_pair, base_url ^ url) :: (List.remove_assoc attr_pair attrs))
| Some url -> `Start_element ((e, tag),
(attr_pair, add_prefix_unless_http base_url url)
:: (List.remove_assoc attr_pair attrs))
| None -> `Start_element ((e, tag), attrs) in
Lwt_io.open_file ~mode:Lwt_io.Input orig_file >>= fun ofile ->
Lwt_io.open_file ~mode:Lwt_io.Output dest_file >>= fun wfile ->
Expand Down
15 changes: 0 additions & 15 deletions static/css/learnocaml_common.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ code, pre, textarea {
line-height: 18px;
}

div.anon-id span.student::before,
div.anon-id li.student::before {
content: attr(data-anon);
}

div.token-id span.student::before,
div.token-id li.student::before {
content: attr(data-token);
}

div.nickname-id span.student::before,
div.nickname-id li.student::before {
content: attr(data-nickname);
}

/* -------------------- fix browser's CSSs ------------------------ */
button > img {
vertical-align: -10%;
Expand Down
12 changes: 12 additions & 0 deletions static/css/learnocaml_partition_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ span.student {
background-color: lightyellow;
cursor: pointer;
}

div.anon-id span.student::before, div.anon-id li.student::before {
content: attr(data-anon);
}

div.token-id span.student::before, div.token-id li.student::before {
content: attr(data-token);
}

div.nickname-id span.student::before, div.nickname-id li.student::before {
content: attr(data-nickname);
}

0 comments on commit 1584a08

Please sign in to comment.