forked from btcpayserver/btcpayserver-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-redirects.js
22 lines (18 loc) · 876 Bytes
/
create-redirects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { mkdirSync, writeFileSync } = require('fs')
const { dirname, join, resolve } = require('path')
const redirects = require('./docs/.vuepress/redirects')
const dist = resolve(__dirname, 'docs', '.vuepress', 'dist')
const exists = filePath => {
try {
const stat = fs.statSync(filePath)
return stat.isFile() || stat.isDirectory()
} catch (err) {
return false
}
}
redirects.forEach(({ path, redirect }) => {
const target = join(dist, path, 'index.html')
if (exists(target)) return
mkdirSync(dirname(target), { recursive: true })
writeFileSync(target, `<!DOCTYPE html><html><title>Redirect</title><link rel="canonical" href="${redirect}"><script>location="${redirect}"</script><meta http-equiv="refresh" content="0;url=${redirect}"><meta name="robots" content="noindex"><a href="${redirect}">Click here if you are not redirected.</a></html>`)
})