-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredirects.js
39 lines (37 loc) · 963 Bytes
/
redirects.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
39
const fs = require('fs')
const { join } = require('path')
const redirects = fs
.readFileSync(join('.', 'redirects.yml'))
.toString()
.split('\n')
.filter(i => i.startsWith('-'))
.map(i =>
i
.replace('-', '')
.trim()
.split(' ')
)
redirects.forEach(redirect => {
const from = redirect[0]
const to = redirect[1].startsWith('/')
? `https://karuna2020.org${redirect[1]}`
: redirect[1]
fs.mkdirSync(join('.', 'dist', from), { recursive: true })
fs.writeFileSync(
join('.', 'dist', from, 'index.html'),
`<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0; url=${to}" />
<script type="text/javascript">
window.location.href = "${to}";
</script>
</head>
<body>
<p><a href="${to}">If you're not redirected, click here</a></p>
</body>
</html>`
)
})