Skip to content

Commit adb52a5

Browse files
authored
Merge pull request #1 from vaniyokk/dev
First release
2 parents 9b1a671 + b5c01d7 commit adb52a5

File tree

7 files changed

+135
-2
lines changed

7 files changed

+135
-2
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
"extends": "standard"
3+
};

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
__tests__
3+
__mocks__
4+
.temp

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
# vuepress-plugin-alias
22
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+
```

index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
})

package.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuepress-plugin-alias",
3-
"version": "1.0.0",
3+
"version": "1.0.0-alpha.1",
44
"description": "Vuepress plugin that generates alias pages for proper redirect handling",
55
"main": "index.js",
66
"publishConfig": {
@@ -22,5 +22,16 @@
2222
"bugs": {
2323
"url": "https://github.com/vaniyokk/vuepress-plugin-alias/issues"
2424
},
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+
}
2637
}

yarn.lock

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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==

0 commit comments

Comments
 (0)