-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgen-webring-routes.js
38 lines (33 loc) · 1.35 KB
/
gen-webring-routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require("fs");
// Import ze froges
const frogs = require("./static/webring/froglist.json");
function makeHtmlRedirect(frog) {
return `
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=${frog.url}">
<script type="text/javascript">
// JS redirect as fallback if the meta tag doesn't work
window.location.href = "${frog.url}"
</script>
<title>Page Redirection</title>
</head>
<body>
<!-- And a link, just in case -->
If you are not redirected automatically, follow this <a href='${frog.url}'>link</a>.
</body>
</html>`;
}
function makeRoutes(frog, nextFrog, prevFrog) {
fs.mkdirSync(`./static/webring/frogs/${frog.name}`, { recursive: true });
fs.appendFileSync(`./static/webring/frogs/${frog.name}.html`, makeHtmlRedirect(frog));
fs.appendFileSync(`./static/webring/frogs/${frog.name}/next.html`, makeHtmlRedirect(nextFrog));
fs.appendFileSync(`./static/webring/frogs/${frog.name}/prev.html`, makeHtmlRedirect(prevFrog));
}
frogs.forEach((frog, i) => {
const nextFrog = frogs.at((i + 1) % frogs.length);
const prevFrog = frogs.at(i - 1); // array.at(-1) returns the last element
makeRoutes(frog, nextFrog, prevFrog);
});