Skip to content

Commit 5b395bc

Browse files
authored
Merge pull request #1059 from Julow/html-meta-generator
html: Output meta charset before any stylesheet
2 parents c80f0cd + 608f24c commit 5b395bc

File tree

379 files changed

+747
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

379 files changed

+747
-698
lines changed

src/html/html_page.ml

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ let html_of_breadcrumbs (breadcrumbs : Types.breadcrumb list) =
8282
make_navigation ~up_url:up.href
8383
(List.rev html @ sep @ [ Html.txt current.name ])
8484

85+
let file_uri ~config ~url (base : Types.uri) file =
86+
match base with
87+
| Types.Absolute uri -> uri ^ "/" ^ file
88+
| Relative uri ->
89+
let page = Url.Path.{ kind = `File; parent = uri; name = file } in
90+
Link.href ~config ~resolve:(Current url) (Url.from_path page)
91+
92+
let default_meta_elements ~config ~url =
93+
let theme_uri = Config.theme_uri config in
94+
let odoc_css_uri = file_uri ~config ~url theme_uri "odoc.css" in
95+
[
96+
Html.meta ~a:[ Html.a_charset "utf-8" ] ();
97+
Html.link ~rel:[ `Stylesheet ] ~href:odoc_css_uri ();
98+
Html.meta
99+
~a:[ Html.a_name "generator"; Html.a_content "odoc %%VERSION%%" ]
100+
();
101+
Html.meta
102+
~a:
103+
[
104+
Html.a_name "viewport";
105+
Html.a_content "width=device-width,initial-scale=1.0";
106+
]
107+
();
108+
]
109+
85110
let page_creator ~config ~url ~uses_katex header breadcrumbs toc content =
86111
let theme_uri = Config.theme_uri config in
87112
let support_uri = Config.support_uri config in
@@ -93,21 +118,13 @@ let page_creator ~config ~url ~uses_katex header breadcrumbs toc content =
93118
Printf.sprintf "%s (%s)" url.name (String.concat "." path)
94119
in
95120

96-
let file_uri (base : Types.uri) file =
97-
match base with
98-
| Types.Absolute uri -> uri ^ "/" ^ file
99-
| Relative uri ->
100-
let page = Url.Path.{ kind = `File; parent = uri; name = file } in
101-
Link.href ~config ~resolve:(Current url) (Url.from_path page)
102-
in
121+
let file_uri = file_uri ~config ~url in
103122
let search_uri uri =
104123
match uri with
105124
| Types.Absolute uri -> uri
106125
| Relative uri ->
107126
Link.href ~config ~resolve:(Current url) (Url.from_path uri)
108127
in
109-
let odoc_css_uri = file_uri theme_uri "odoc.css" in
110-
let highlight_js_uri = file_uri support_uri "highlight.pack.js" in
111128
let search_scripts =
112129
match search_uris with
113130
| [] -> []
@@ -142,30 +159,19 @@ let search_urls = %s;
142159
(Html.txt "");
143160
]
144161
in
145-
let default_meta_elements =
146-
[
147-
Html.link ~rel:[ `Stylesheet ] ~href:odoc_css_uri ();
148-
Html.meta ~a:[ Html.a_charset "utf-8" ] ();
149-
Html.meta
150-
~a:[ Html.a_name "generator"; Html.a_content "odoc %%VERSION%%" ]
151-
();
152-
Html.meta
153-
~a:
154-
[
155-
Html.a_name "viewport";
156-
Html.a_content "width=device-width,initial-scale=1.0";
157-
]
158-
();
159-
Html.script ~a:[ Html.a_src highlight_js_uri ] (Html.txt "");
160-
Html.script (Html.txt "hljs.initHighlightingOnLoad();");
161-
]
162-
in
163162
let meta_elements =
164-
if uses_katex then
165-
let katex_css_uri = file_uri theme_uri "katex.min.css" in
166-
let katex_js_uri = file_uri support_uri "katex.min.js" in
167-
default_meta_elements
168-
@ [
163+
let highlightjs_meta =
164+
let highlight_js_uri = file_uri support_uri "highlight.pack.js" in
165+
[
166+
Html.script ~a:[ Html.a_src highlight_js_uri ] (Html.txt "");
167+
Html.script (Html.txt "hljs.initHighlightingOnLoad();");
168+
]
169+
in
170+
let katex_meta =
171+
if uses_katex then
172+
let katex_css_uri = file_uri theme_uri "katex.min.css" in
173+
let katex_js_uri = file_uri support_uri "katex.min.js" in
174+
[
169175
Html.link ~rel:[ `Stylesheet ] ~href:katex_css_uri ();
170176
Html.script ~a:[ Html.a_src katex_js_uri ] (Html.txt "");
171177
Html.script
@@ -185,7 +191,9 @@ let search_urls = %s;
185191
});
186192
|});
187193
]
188-
else default_meta_elements
194+
else []
195+
in
196+
default_meta_elements ~config ~url @ highlightjs_meta @ katex_meta
189197
in
190198
let meta_elements = meta_elements @ search_scripts in
191199
Html.head (Html.title (Html.txt title_string)) meta_elements
@@ -229,35 +237,11 @@ let path_of_module_of_source ppf url =
229237
| None -> ()
230238

231239
let src_page_creator ~breadcrumbs ~config ~url ~header name content =
232-
let theme_uri = Config.theme_uri config in
233240
let head : Html_types.head Html.elt =
234241
let title_string =
235242
Format.asprintf "Source: %s%a" name path_of_module_of_source url
236243
in
237-
let file_uri (base : Types.uri) file =
238-
match base with
239-
| Types.Absolute uri -> uri ^ "/" ^ file
240-
| Relative uri ->
241-
let page = Url.Path.{ kind = `File; parent = uri; name = file } in
242-
Link.href ~config ~resolve:(Current url) (Url.from_path page)
243-
in
244-
let odoc_css_uri = file_uri theme_uri "odoc.css" in
245-
let meta_elements =
246-
[
247-
Html.link ~rel:[ `Stylesheet ] ~href:odoc_css_uri ();
248-
Html.meta ~a:[ Html.a_charset "utf-8" ] ();
249-
Html.meta
250-
~a:[ Html.a_name "generator"; Html.a_content "odoc %%VERSION%%" ]
251-
();
252-
Html.meta
253-
~a:
254-
[
255-
Html.a_name "viewport";
256-
Html.a_content "width=device-width,initial-scale=1.0";
257-
]
258-
();
259-
]
260-
in
244+
let meta_elements = default_meta_elements ~config ~url in
261245
Html.head (Html.title (Html.txt title_string)) meta_elements
262246
in
263247
let body =

test/generators/html/Alerts-Top1.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Top1 (Alerts.Top1)</title>
4-
<link rel="stylesheet" href="odoc.css"/><meta charset="utf-8"/>
3+
<head><title>Top1 (Alerts.Top1)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
55
<meta name="generator" content="odoc %%VERSION%%"/>
66
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
77
<script src="highlight.pack.js"></script>

test/generators/html/Alerts-Top2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Top2 (Alerts.Top2)</title>
4-
<link rel="stylesheet" href="odoc.css"/><meta charset="utf-8"/>
3+
<head><title>Top2 (Alerts.Top2)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
55
<meta name="generator" content="odoc %%VERSION%%"/>
66
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
77
<script src="highlight.pack.js"></script>

test/generators/html/Alerts.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Alerts (Alerts)</title><link rel="stylesheet" href="odoc.css"/>
4-
<meta charset="utf-8"/><meta name="generator" content="odoc %%VERSION%%"/>
3+
<head><title>Alerts (Alerts)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
5+
<meta name="generator" content="odoc %%VERSION%%"/>
56
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
67
<script src="highlight.pack.js"></script>
78
<script>hljs.initHighlightingOnLoad();</script>

test/generators/html/Alias-X.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>X (Alias.X)</title><link rel="stylesheet" href="odoc.css"/>
4-
<meta charset="utf-8"/><meta name="generator" content="odoc %%VERSION%%"/>
3+
<head><title>X (Alias.X)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
5+
<meta name="generator" content="odoc %%VERSION%%"/>
56
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
67
<script src="highlight.pack.js"></script>
78
<script>hljs.initHighlightingOnLoad();</script>

test/generators/html/Alias.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Alias (Alias)</title><link rel="stylesheet" href="odoc.css"/>
4-
<meta charset="utf-8"/><meta name="generator" content="odoc %%VERSION%%"/>
3+
<head><title>Alias (Alias)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
5+
<meta name="generator" content="odoc %%VERSION%%"/>
56
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
67
<script src="highlight.pack.js"></script>
78
<script>hljs.initHighlightingOnLoad();</script>

test/generators/html/Bugs.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Bugs (Bugs)</title><link rel="stylesheet" href="odoc.css"/>
4-
<meta charset="utf-8"/><meta name="generator" content="odoc %%VERSION%%"/>
3+
<head><title>Bugs (Bugs)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
5+
<meta name="generator" content="odoc %%VERSION%%"/>
56
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
67
<script src="highlight.pack.js"></script>
78
<script>hljs.initHighlightingOnLoad();</script>

test/generators/html/Bugs_post_406-class-let_open'.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head><title>let_open' (Bugs_post_406.let_open')</title>
4-
<link rel="stylesheet" href="odoc.css"/><meta charset="utf-8"/>
4+
<meta charset="utf-8"/><link rel="stylesheet" href="odoc.css"/>
55
<meta name="generator" content="odoc %%VERSION%%"/>
66
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
77
<script src="highlight.pack.js"></script>

test/generators/html/Bugs_post_406-class-type-let_open.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head><title>let_open (Bugs_post_406.let_open)</title>
4-
<link rel="stylesheet" href="odoc.css"/><meta charset="utf-8"/>
4+
<meta charset="utf-8"/><link rel="stylesheet" href="odoc.css"/>
55
<meta name="generator" content="odoc %%VERSION%%"/>
66
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
77
<script src="highlight.pack.js"></script>

test/generators/html/Bugs_post_406.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
3-
<head><title>Bugs_post_406 (Bugs_post_406)</title>
4-
<link rel="stylesheet" href="odoc.css"/><meta charset="utf-8"/>
3+
<head><title>Bugs_post_406 (Bugs_post_406)</title><meta charset="utf-8"/>
4+
<link rel="stylesheet" href="odoc.css"/>
55
<meta name="generator" content="odoc %%VERSION%%"/>
66
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
77
<script src="highlight.pack.js"></script>

0 commit comments

Comments
 (0)