-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (31 loc) · 1005 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
31
32
33
34
35
36
37
const fs = require('fs-extra')
const path = require('path')
function getTemplate (path) {
const result = '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta charset="utf-8">' +
'<title>Redirecting...</title>' +
'<link rel="canonical" href="' + path + '">' +
'<meta http-equiv="refresh" content="0; url=' + path + '">' +
'</head>' +
'</html>'
return result
}
module.exports = (options, ctx) => ({
async generated (pagePaths) {
const { pages, outDir } = ctx
pages.filter(({ frontmatter }) => {
return frontmatter.alias || frontmatter.aliases
}).forEach(page => {
let aliases = page.frontmatter.alias || page.frontmatter.aliases
if (!Array.isArray(aliases)) aliases = [aliases]
if (!aliases.length) return
const content = getTemplate(page.path)
aliases.forEach(async alias => {
const aliasPagePath = path.resolve(outDir, alias)
await fs.outputFile(aliasPagePath, content)
})
})
}
})