Newer
Older
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
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs');
const path = require('path');
function redirect (oldPath, newPath) {
const oldRelativePath = path.join(__dirname, '../', './_site/', oldPath);
const newRelativePath = path.join(__dirname, '../', './_site/', newPath);
const newSitePath = path.join('https://resynth1943.net', newPath);
fs.mkdirSync(path.dirname(oldRelativePath), { recursive: true });
console.log(`Redirecting ${oldPath} → ${newPath}`);
fs.writeFileSync(oldRelativePath, `\
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<!-- Pleace this snippet right after opening the head tag to make it work properly -->
<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->
<!-- Addendum: this is actually generated via a script, not their web tool. -->
<!-- Nevertheless, I have stolen their code, so let's leave the license there. -->
<!-- REDIRECTING STARTS -->
<link rel="canonical" href="${newSitePath}" />
<noscript>
<meta http-equiv="refresh" content="0;URL=${newSitePath}">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
var url = "${newSitePath}";
if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
{
document.write("redirecting..."); // Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
}
else { window.location.replace(url); } // All other browsers
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->
</head>
</html>
`);
}
module.exports = redirect;