Skip to content

Commit b2843d7

Browse files
committed
Website: deduplicate nav code
Each page has its own code for the side bar navigation. Adding a page to this nav bar involves changing every single page, which is error-prone. Simplify maintenance of the side bar nav by moving its code into a single place. This commit should not change behavior.
1 parent d68967f commit b2843d7

File tree

14 files changed

+112
-108
lines changed

14 files changed

+112
-108
lines changed

website/public/benchmarks/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,7 @@
3737
<header>
3838
<h1><a href="../">quick-lint-js</a></h1>
3939
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
40-
<nav>
41-
<ul>
42-
<li class="side-bar-only"><a href="..">Home</a></li>
43-
<li><a href="../install/">Install</a></li>
44-
<li><a href="../demo/">Try online</a></li>
45-
<li><a href="../errors/">Error docs</a></li>
46-
<li><a href="../cli/">CLI docs</a></li>
47-
<li class="current-page">Benchmarks</li>
48-
<li>
49-
<a href="https://github.com/quick-lint/quick-lint-js"
50-
>Code on GitHub</a
51-
>
52-
</li>
53-
</ul>
54-
</nav>
40+
<%- await include("../common-nav.ejs.html") %>
5541
</header>
5642

5743
<main>

website/public/cli/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,7 @@
2121
<header>
2222
<h1><a href="../">quick-lint-js</a></h1>
2323
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
24-
<nav>
25-
<ul>
26-
<li class="side-bar-only"><a href="..">Home</a></li>
27-
<li><a href="../install/">Install</a></li>
28-
<li><a href="../demo/">Try online</a></li>
29-
<li><a href="../errors/">Error docs</a></li>
30-
<li class="current-page">CLI docs</li>
31-
<li><a href="../benchmarks/">Benchmarks</a></li>
32-
<li>
33-
<a href="https://github.com/quick-lint/quick-lint-js"
34-
>Code on GitHub</a
35-
>
36-
</li>
37-
</ul>
38-
</nav>
24+
<%- await include("../common-nav.ejs.html") %>
3925
</header>
4026

4127
<main>

website/public/common-nav.ejs.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<%#
2+
<!-- Copyright (C) 2020 Matthew Glazar -->
3+
<!-- See end of file for extended copyright information. -->
4+
%>
5+
6+
<script>
7+
//<%
8+
let path = await import("path");
9+
function makeRelativeURI(uri) {
10+
return path.posix.relative(currentURI, uri) + "/";
11+
}
12+
13+
let navigationPages = [
14+
["/install/", "Install"],
15+
["/demo/", "Try online"],
16+
["/errors/", "Error docs"],
17+
["/cli/", "CLI docs"],
18+
["/benchmarks/", "Benchmarks"],
19+
];
20+
//%>
21+
</script>
22+
23+
<nav>
24+
<ul>
25+
<% if (currentURI !== "/") { %>
26+
<li class="side-bar-only">
27+
<a href="<%= makeRelativeURI('/') %>">Home</a>
28+
</li>
29+
<% } %> <% for (let [pageURL, pageTitle] of navigationPages) { %> <% if
30+
(pageURL === currentURI) { %>
31+
<li class="current-page"><%= pageTitle %></li>
32+
<% } else { %>
33+
<li><a href="<%= makeRelativeURI(pageURL) %>"><%= pageTitle %></a></li>
34+
<% } %> <% } %>
35+
<li>
36+
<a href="https://github.com/quick-lint/quick-lint-js">Code on GitHub</a>
37+
</li>
38+
</ul>
39+
</nav>
40+
41+
<%#
42+
<!--
43+
quick-lint-js finds bugs in JavaScript programs.
44+
Copyright (C) 2020 Matthew Glazar
45+
46+
This file is part of quick-lint-js.
47+
48+
quick-lint-js is free software: you can redistribute it and/or modify
49+
it under the terms of the GNU General Public License as published by
50+
the Free Software Foundation, either version 3 of the License, or
51+
(at your option) any later version.
52+
53+
quick-lint-js is distributed in the hope that it will be useful,
54+
but WITHOUT ANY WARRANTY; without even the implied warranty of
55+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56+
GNU General Public License for more details.
57+
58+
You should have received a copy of the GNU General Public License
59+
along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
60+
-->
61+
%>

website/public/demo/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,7 @@
108108
<header>
109109
<h1><a href="../">quick-lint-js</a></h1>
110110
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
111-
<nav>
112-
<ul>
113-
<li class="side-bar-only"><a href="..">Home</a></li>
114-
<li><a href="../install/">Install</a></li>
115-
<li class="current-page">Try online</li>
116-
<li><a href="../errors/">Error docs</a></li>
117-
<li><a href="../cli/">CLI docs</a></li>
118-
<li><a href="../benchmarks/">Benchmarks</a></li>
119-
<li>
120-
<a href="https://github.com/quick-lint/quick-lint-js"
121-
>Code on GitHub</a
122-
>
123-
</li>
124-
</ul>
125-
</nav>
111+
<%- await include("../common-nav.ejs.html") %>
126112
</header>
127113

128114
<main>

website/public/errors/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,7 @@
6161
<header>
6262
<h1><a href="../">quick-lint-js</a></h1>
6363
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
64-
<nav>
65-
<ul>
66-
<li class="side-bar-only"><a href="..">Home</a></li>
67-
<li><a href="../install/">Install</a></li>
68-
<li><a href="../demo/">Try online</a></li>
69-
<li class="current-page">Error docs</li>
70-
<li><a href="../cli/">CLI docs</a></li>
71-
<li><a href="../benchmarks/">Benchmarks</a></li>
72-
<li>
73-
<a href="https://github.com/quick-lint/quick-lint-js"
74-
>Code on GitHub</a
75-
>
76-
</li>
77-
</ul>
78-
</nav>
64+
<%- await include("../common-nav.ejs.html") %>
7965
</header>
8066

8167
<main>

website/public/hiring/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@
1414
<body>
1515
<header>
1616
<h1><a href="..">quick-lint-js</a></h1>
17-
<nav>
18-
<ul>
19-
<li class="side-bar-only"><a href="..">Home</a></li>
20-
<li><a href="../install/">Install</a></li>
21-
<li><a href="../demo/">Try online</a></li>
22-
<li><a href="../errors/">Error docs</a></li>
23-
<li><a href="../cli/">CLI docs</a></li>
24-
<li><a href="../benchmarks/">Benchmarks</a></li>
25-
<li>
26-
<a href="https://github.com/quick-lint/quick-lint-js"
27-
>Code on GitHub</a
28-
>
29-
</li>
30-
</ul>
31-
</nav>
17+
<%- await include("../common-nav.ejs.html") %>
3218
</header>
3319

3420
<main>

website/public/index.ejs.html

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,7 @@
113113
<header>
114114
<h1>quick-lint-js</h1>
115115
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
116-
<nav>
117-
<ul>
118-
<li><a href="install/">Install</a></li>
119-
<li><a href="demo/">Try online</a></li>
120-
<li><a href="errors/">Error docs</a></li>
121-
<li><a href="cli/">CLI docs</a></li>
122-
<li><a href="benchmarks/">Benchmarks</a></li>
123-
<li>
124-
<a href="https://github.com/quick-lint/quick-lint-js"
125-
>Code on GitHub</a
126-
>
127-
</li>
128-
</ul>
129-
</nav>
116+
<%- await include("./common-nav.ejs.html") %>
130117
</header>
131118

132119
<main>

website/public/install/index.ejs.html

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,7 @@
128128
<header>
129129
<h1><a href="..">quick-lint-js</a></h1>
130130
<p class="tag-line">quick-lint-js finds bugs in JavaScript programs.</p>
131-
<nav>
132-
<ul>
133-
<li class="side-bar-only"><a href="..">Home</a></li>
134-
<li class="current-page">Install</li>
135-
<li><a href="../demo/">Try online</a></li>
136-
<li><a href="../errors/">Error docs</a></li>
137-
<li><a href="../cli/">CLI docs</a></li>
138-
<li><a href="../benchmarks/">Benchmarks</a></li>
139-
<li>
140-
<a href="https://github.com/quick-lint/quick-lint-js"
141-
>Code on GitHub</a
142-
>
143-
</li>
144-
</ul>
145-
</nav>
131+
<%- await include("../common-nav.ejs.html") %>
146132
</header>
147133

148134
<main>

website/run-build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function mainAsync() {
4444
let outPath = path.join(targetDirectory, instruction.destinationPath);
4545
console.log(`build EJS: ${ejsPath} -> ${outPath}`);
4646
await fs.promises.mkdir(path.dirname(outPath), { recursive: true });
47-
let out = await router.renderEJSFile(ejsPath);
47+
let out = await router.renderEJSFile(ejsPath, instruction.ejsVariables);
4848
fs.promises.writeFile(outPath, out);
4949
break;
5050

website/src/build.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ async function makeBuildInstructionsImplAsync(router, instructions, basePath) {
7373
type: "build-ejs",
7474
sourcePath: classifiedDirectory.path,
7575
destinationPath: path.join(basePath, "index.html"),
76+
ejsVariables: {
77+
currentURI: basePath === "" ? "/" : `/${basePath}/`,
78+
},
7679
});
7780
break;
7881

0 commit comments

Comments
 (0)