-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (22 loc) · 992 Bytes
/
index.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
// Load all the urls from redirects.yml
const YAML = require('yaml')
// Read redirects files
const fs = require('fs')
const path = require('path')
const redirectsFile = fs.readFileSync(path.join(__dirname, 'redirects.yml'), 'utf-8')
console.log(redirectsFile)
//Parse YAML
const redirects = YAML.parse(redirectsFile)
console.log(redirects)
// Generate an html page for each redirect url from template.html
const templateHTML = fs.readFileSync(path.join(__dirname, 'template.html'), 'utf-8')
// Loop through all url redirects, and generate an html page
for (let [slug, url] of Object.entries(redirects)) {
console.log('Generating HTML Page for ', slug)
const html = templateHTML.replaceAll('https://example.com', url)
// Create folder for each slug
const folderPath = path.join(__dirname, 'out', slug)
fs.mkdirSync(folderPath, { recursive: true })
// Create an index.html in each slug directory
fs.writeFileSync(path.join(folderPath, 'index.html'), html)
}