Skip to content

Commit 40b3da8

Browse files
shigmaulivz
authored andcommitted
feat: plugin clean urls (#1339)
1 parent 6d0f4a3 commit 40b3da8

File tree

7 files changed

+159
-0
lines changed

7 files changed

+159
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__tests__
2+
__mocks__
3+
.temp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @vuepress/plugin-clean-urls
2+
3+
> clean urls plugin for vuepress
4+
5+
See [documentation](https://vuepress.vuejs.org/plugin/official/plugin-clean-urls.html).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = (options = {}, context) => {
2+
const {
3+
normalSuffix = '',
4+
indexSuffix = '/'
5+
} = options
6+
7+
return {
8+
extendPageData (page) {
9+
const { regularPath, frontmatter = {}} = page
10+
if (frontmatter.permalink) return
11+
if (regularPath.endsWith('.html')) {
12+
// normal path
13+
// e.g. foo/bar.md -> foo/bar.html
14+
page.path = regularPath.slice(0, -5) + normalSuffix
15+
} else if (regularPath.endsWith('/')) {
16+
// index path
17+
// e.g. foo/index.md -> foo/
18+
page.path = regularPath.slice(0, -1) + indexSuffix
19+
}
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@vuepress/plugin-clean-urls",
3+
"version": "1.0.0-alpha.39",
4+
"description": "clean urls plugin for vuepress",
5+
"main": "index.js",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/vuejs/vuepress.git",
12+
"directory": "packages/@vuepress/plugin-clean-urls"
13+
},
14+
"keywords": [
15+
"documentation",
16+
"vue",
17+
"vuepress",
18+
"generator"
19+
],
20+
"author": "Shigma <[email protected]>",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/vuejs/vuepress/issues"
24+
},
25+
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-clean-urls#readme"
26+
}

packages/docs/docs/.vuepress/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ function getPluginSidebar (pluginTitle, pluginIntro, officialPluginTitle) {
143143
'official/plugin-medium-zoom',
144144
'official/plugin-back-to-top',
145145
'official/plugin-register-components',
146+
'official/plugin-clean-urls'
146147
]
147148
}
148149
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: clean-urls
3+
metaTitle: A plugin of automatically generating clean urls | VuePress
4+
---
5+
6+
# [@vuepress/plugin-clean-urls](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-clean-urls)
7+
8+
> A plugin of automatically generating clean urls
9+
10+
## Install
11+
12+
```bash
13+
yarn add -D @vuepress/plugin-clean-urls
14+
# OR npm install -D @vuepress/plugin-clean-urls
15+
```
16+
17+
## Usage
18+
19+
```javascript
20+
module.exports = {
21+
plugins: ['@vuepress/clean-urls']
22+
}
23+
```
24+
25+
## Options
26+
27+
### normalSuffix
28+
29+
- Type: `string`
30+
- Default: `''`
31+
32+
The suffix for normal pages. For example, `foo/bar.md` will become:
33+
34+
- `foo/bar.html` by default (without this plugin)
35+
- `foo/bar/` (with `normalSuffix` set to `'/'`)
36+
- `foo/bar` (with `normalSuffix` set to `''`)
37+
38+
### indexSuffix
39+
40+
- Type: `string`
41+
- Default: `'/'`
42+
43+
The suffix for index pages. For example, `foo/index.md` will become:
44+
45+
- `foo/` by default (without this plugin)
46+
- `foo` (with `indexSuffix` set to `''`)
47+
- `foo/index.html` (with `indexSuffix` set to `'/index.html'`)
48+
49+
::: tip
50+
An index page is a page with a file name of index.md or readme.md (case insensitive).
51+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: clean-urls
3+
metaTitle: 自动生成简洁链接的插件 | VuePress
4+
---
5+
6+
# [@vuepress/plugin-clean-urls](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-clean-urls)
7+
8+
> 自动生成简洁链接的插件
9+
10+
## 安装
11+
12+
```bash
13+
yarn add -D @vuepress/plugin-clean-urls
14+
# OR npm install -D @vuepress/plugin-clean-urls
15+
```
16+
17+
## 使用
18+
19+
```javascript
20+
module.exports = {
21+
plugins: ['@vuepress/clean-urls']
22+
}
23+
```
24+
25+
## 选项
26+
27+
### normalSuffix
28+
29+
- 类型: `string`
30+
- 默认值: `''`
31+
32+
普通页面的链接后缀。举个例子,`foo/bar.md` 会自动变成:
33+
34+
- `foo/bar.html` 在默认情况下(未安装本插件时)
35+
- `foo/bar/`(当 `normalSuffix` 被设为 `'/'` 时)
36+
- `foo/bar`(当 `normalSuffix` 被设为 `''` 时)
37+
38+
### indexSuffix
39+
40+
- 类型: `string`
41+
- 默认值: `'/'`
42+
43+
索引页面的链接后缀。举个例子,`foo/index.md` 会自动变成:
44+
45+
- `foo/` 在默认情况下(未安装本插件时)
46+
- `foo`(当 `indexSuffix` 被设为 `''` 时)
47+
- `foo/index.html`(当 `indexSuffix` 被设为 `'/index.html'` 时)
48+
49+
::: tip
50+
索引页面是指文件名为 index.md 或者 readme.md 的页面(不区分大小写)。
51+
:::

0 commit comments

Comments
 (0)