webring
This commit is contained in:
commit
06547a0e2d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
node_modules
|
||||||
|
webring.txt
|
33
index.mjs
Normal file
33
index.mjs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import * as fs from 'node:fs';
|
||||||
|
import express from 'express';
|
||||||
|
|
||||||
|
const sites = fs.readFileSync('./webring.txt', 'utf-8')
|
||||||
|
// split lines
|
||||||
|
.split(/\r?\n/)
|
||||||
|
// trim whitespace from each line
|
||||||
|
.map(site => site.trim())
|
||||||
|
// exclude empty lines and lines that start with # because why not
|
||||||
|
.filter(site => site && !site.startsWith('#'));
|
||||||
|
|
||||||
|
console.log(sites);
|
||||||
|
|
||||||
|
// modulo that does the right thing with negatives
|
||||||
|
// https://stackoverflow.com/a/4467559
|
||||||
|
const mod = (n, m) => ((n % m) + m) % m;
|
||||||
|
|
||||||
|
function handle (offset, request, response) {
|
||||||
|
const from = request.query.from;
|
||||||
|
const index = sites.findIndex(site => site === from);
|
||||||
|
if (!from || index === -1) {
|
||||||
|
response.status(400).send('the provided site is not in the webring');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
response.redirect(301, sites[mod(index + offset, sites.length)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
express()
|
||||||
|
.get('/prev', (request, response) => handle(-1, request, response))
|
||||||
|
.get('/next', (request, response) => handle(+1, request, response))
|
||||||
|
.listen(process.env.PORT || 8080, () => {
|
||||||
|
console.log('doing the thing');
|
||||||
|
})
|
1036
package-lock.json
generated
Normal file
1036
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
15
package.json
Normal file
15
package.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"name": "webring-shit",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.18.2"
|
||||||
|
}
|
||||||
|
}
|
4
webring.txt.sample
Normal file
4
webring.txt.sample
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
https://example.com
|
||||||
|
https://example.org
|
||||||
|
https://example.net/~someone
|
||||||
|
https://example.net/~otherone
|
Loading…
Reference in a new issue