Skip to content

Commit 31c7d55

Browse files
authored
Merge pull request #1 from teofum/webring-test
Webring test
2 parents 6494f73 + c138cc3 commit 31c7d55

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
node-version: 18
2121
cache: npm
2222

23+
- name: test thing
24+
run: node gen-webring-routes.js
25+
2326
- name: Install dependencies
2427
run: npm ci
2528
- name: Build website

gen-webring-routes.js

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

static/webring/froglist.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"name": "gp-blog",
4+
"url": "https://graphics-programming.org/"
5+
},
6+
{
7+
"name": "bluescreen",
8+
"url": "https://fumagalli.ar/"
9+
}
10+
]

0 commit comments

Comments
 (0)