File tree 1 file changed +32
-1
lines changed
1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change
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
+
1
17
module . exports = ( options , ctx ) => ( {
2
18
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
+ } )
4
35
}
5
36
} )
You can’t perform that action at this time.
0 commit comments