Some code to create classic HTML redirect pages. For reference, see:
https://www.w3docs.com/snippets/html/how-to-redirect-a-web-page-in-html.html
Some code to create classic HTML redirect pages. For reference, see:
https://www.w3docs.com/snippets/html/how-to-redirect-a-web-page-in-html.html
2001_03_04_archive.html | |
2001_03_11_archive.html | |
2001_03_18_archive.html | |
2001_03_25_archive.html | |
2001_04_01_archive.html | |
2005_02_27_archive.html | |
2005_03_06_archive.html | |
archive-detail.html | |
archive.html | |
index.html |
const fs = require('fs') | |
const byline = require('byline') | |
const pug = require('pug') | |
const stream = byline(fs.createReadStream('files.txt')) | |
const re = /(?<year_str>\d\d\d\d)_(?<month_str>\d\d)_(?<day_str>\d\d)_archive.html/ | |
const fn = pug.compileFile('redirector.pug', { pretty: true, debug: false }) | |
const { DateTime } = require('luxon') | |
function writeRedirectFile (fileName, newUrl, refreshValue) { | |
const ws = fs.createWriteStream(fileName) | |
const locals = { fileName: fileName, newUrl: newUrl, refreshValue: refreshValue } | |
const html = fn(locals) | |
ws.write(html) | |
ws.end() | |
} | |
stream.on('data', function (line) { | |
const fileName = line.toString() | |
const match = re.exec(fileName) | |
if (match != null) { | |
const minDate = `${match.groups.year_str}-${match.groups.month_str}-${match.groups.day_str}` | |
const maxDate = DateTime.fromISO(minDate).plus({ days: 7 }).toISODate() | |
const newUrl = `http://blog.rickumali.com/search?updated-min=${minDate}T00:00:00-05:00&updated-max=${maxDate}T00:00:00-05:00&reverse-paginate=true` | |
const refreshValue = `0; url=${newUrl}` | |
writeRedirectFile(fileName, newUrl, refreshValue) | |
} else { | |
const newUrl = 'http://blog.rickumali.com/' | |
const refreshValue = `0; url=${newUrl}` | |
writeRedirectFile(fileName, newUrl, refreshValue) | |
} | |
}) |
{ | |
"name": "oldblog-redirects", | |
"version": "1.0.0", | |
"description": "Simple I/O to make HTML files from a list of files", | |
"main": "index.js", | |
"private": true, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ | |
"HTML", | |
"byline" | |
], | |
"author": "Rick Umali", | |
"license": "MIT", | |
"dependencies": { | |
"byline": "^5.0.0", | |
"luxon": "^1.26.0", | |
"pug": "^3.0.2" | |
}, | |
"devDependencies": { | |
"standard": "^16.0.3" | |
} | |
} |
head | |
title BLOG Page Permanently Moved | |
meta(http-equiv='refresh', content=refreshValue) | |
meta(charset='utf-8') | |
body | |
// 302 Redirecting to New Location | |
center | |
h1 BLOG Page Permanently Moved | |
h2 This page will automatically refresh. | |
p (Click link below if page does not refresh.) | |
p | |
a(href=newUrl) #{newUrl} | |
p | |
sm Rick Umali |