Skip to content

Commit f593dab

Browse files
committed
Add basic alias page generation
1 parent fe8c7c6 commit f593dab

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
1+
const { fs, path } = require('@vuepress/shared-utils');
2+
3+
function getTemplate(path) {
4+
const result = '<!DOCTYPE html>' +
5+
'<html>' +
6+
'<head>' +
7+
'<meta charset="utf-8">' +
8+
'<title>Redirecting...</title>' +
9+
'<link rel="canonical" href="' + path + '">' +
10+
'<meta http-equiv="refresh" content="0; url=' + path + '">' +
11+
'</head>' +
12+
'</html>';
13+
14+
return result;
15+
}
16+
117
module.exports = (options, ctx) => ({
218
async generated (pagePaths) {
3-
console.log(ctx)
19+
const { pages, outDir } = ctx;
20+
21+
pages.filter(({frontmatter}) => {
22+
return frontmatter.alias || frontmatter.aliases;
23+
}).forEach(page => {
24+
let aliases = page.frontmatter.alias || page.frontmatter.aliases;
25+
if (!Array.isArray(aliases)) aliases = [aliases];
26+
if (!aliases.length) return;
27+
28+
const content = getTemplate(page.path);
29+
30+
aliases.forEach(async alias => {
31+
const aliasPagePath = path.resolve(outDir, alias);
32+
await fs.outputFile(aliasPagePath, content);
33+
});
34+
})
435
}
536
})

0 commit comments

Comments
 (0)