File tree 7 files changed +135
-2
lines changed
7 files changed +135
-2
lines changed Original file line number Diff line number Diff line change
1
+ root = true
2
+
3
+ [* ]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ "extends" : "standard"
3
+ } ;
Original file line number Diff line number Diff line change
1
+ node_modules
2
+ __tests__
3
+ __mocks__
4
+ .temp
Original file line number Diff line number Diff line change 1
1
# vuepress-plugin-alias
2
2
Vuepress plugin that generates alias pages for proper redirect handling
3
+
4
+ ## Install
5
+
6
+ * Yarn
7
+
8
+ ``` sh
9
+ yarn add vuepress-plugin-alias
10
+ ```
11
+ * NPM
12
+
13
+ ``` sh
14
+ npm install vuepress-plugin-sitemap
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Vuepress v1.x
20
+
21
+ ``` js
22
+ // .vuepress/config.js
23
+ module .exports = {
24
+ plugins: [ ' alias' ]
25
+ }
26
+ ```
27
+
28
+ and in your front-matter add alias to redirect from
29
+
30
+ ``` md
31
+ ---
32
+ alias: old-link.html
33
+ ---
34
+ ```
35
+ or a list of aliases
36
+ ``` md
37
+ ---
38
+ aliases:
39
+ - old-link1.html
40
+ - old-link2.html
41
+ ---
42
+ ```
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs-extra' )
2
+ const path = require ( 'path' )
3
+
4
+ function getTemplate ( path ) {
5
+ const result = '<!DOCTYPE html>' +
6
+ '<html>' +
7
+ '<head>' +
8
+ '<meta charset="utf-8">' +
9
+ '<title>Redirecting...</title>' +
10
+ '<link rel="canonical" href="' + path + '">' +
11
+ '<meta http-equiv="refresh" content="0; url=' + path + '">' +
12
+ '</head>' +
13
+ '</html>'
14
+
15
+ return result
16
+ }
17
+
18
+ module . exports = ( options , ctx ) => ( {
19
+ async generated ( pagePaths ) {
20
+ const { pages, outDir } = ctx
21
+
22
+ pages . filter ( ( { frontmatter } ) => {
23
+ return frontmatter . alias || frontmatter . aliases
24
+ } ) . forEach ( page => {
25
+ let aliases = page . frontmatter . alias || page . frontmatter . aliases
26
+ if ( ! Array . isArray ( aliases ) ) aliases = [ aliases ]
27
+ if ( ! aliases . length ) return
28
+
29
+ const content = getTemplate ( page . path )
30
+
31
+ aliases . forEach ( async alias => {
32
+ const aliasPagePath = path . resolve ( outDir , alias )
33
+ await fs . outputFile ( aliasPagePath , content )
34
+ } )
35
+ } )
36
+ }
37
+ } )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vuepress-plugin-alias" ,
3
- "version" : " 1.0.0" ,
3
+ "version" : " 1.0.0-alpha.1 " ,
4
4
"description" : " Vuepress plugin that generates alias pages for proper redirect handling" ,
5
5
"main" : " index.js" ,
6
6
"publishConfig" : {
22
22
"bugs" : {
23
23
"url" : " https://github.com/vaniyokk/vuepress-plugin-alias/issues"
24
24
},
25
- "homepage" : " https://github.com/vaniyokk/vuepress-plugin-alias#readme"
25
+ "homepage" : " https://github.com/vaniyokk/vuepress-plugin-alias#readme" ,
26
+ "dependencies" : {
27
+ "fs-extra" : " ^7.0.1"
28
+ },
29
+ "devDependencies" : {
30
+ "eslint" : " ^5.10.0" ,
31
+ "eslint-config-standard" : " ^12.0.0" ,
32
+ "eslint-plugin-import" : " ^2.14.0" ,
33
+ "eslint-plugin-node" : " ^8.0.0" ,
34
+ "eslint-plugin-promise" : " ^4.0.1" ,
35
+ "eslint-plugin-standard" : " ^4.0.0"
36
+ }
26
37
}
Original file line number Diff line number Diff line change
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ fs-extra@^7.0.1 :
6
+ version "7.0.1"
7
+ resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
8
+ integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
9
+ dependencies :
10
+ graceful-fs "^4.1.2"
11
+ jsonfile "^4.0.0"
12
+ universalify "^0.1.0"
13
+
14
+ graceful-fs@^4.1.2, graceful-fs@^4.1.6 :
15
+ version "4.1.15"
16
+ resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
17
+ integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
18
+
19
+ jsonfile@^4.0.0 :
20
+ version "4.0.0"
21
+ resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
22
+ integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
23
+ optionalDependencies :
24
+ graceful-fs "^4.1.6"
25
+
26
+ universalify@^0.1.0 :
27
+ version "0.1.2"
28
+ resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
29
+ integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
You can’t perform that action at this time.
0 commit comments