forked from btcpayserver/btcpayserver-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-redirects.js
25 lines (21 loc) · 888 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
23
24
25
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>`
)
})