Skip to content

Commit

Permalink
feat: plugin clean urls (#1339)
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma authored and ulivz committed Feb 26, 2019
1 parent 6d0f4a3 commit 40b3da8
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@vuepress/plugin-clean-urls/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__tests__
__mocks__
.temp
5 changes: 5 additions & 0 deletions packages/@vuepress/plugin-clean-urls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @vuepress/plugin-clean-urls

> clean urls plugin for vuepress
See [documentation](https://vuepress.vuejs.org/plugin/official/plugin-clean-urls.html).
22 changes: 22 additions & 0 deletions packages/@vuepress/plugin-clean-urls/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = (options = {}, context) => {
const {
normalSuffix = '',
indexSuffix = '/'
} = options

return {
extendPageData (page) {
const { regularPath, frontmatter = {}} = page
if (frontmatter.permalink) return
if (regularPath.endsWith('.html')) {
// normal path
// e.g. foo/bar.md -> foo/bar.html
page.path = regularPath.slice(0, -5) + normalSuffix
} else if (regularPath.endsWith('/')) {
// index path
// e.g. foo/index.md -> foo/
page.path = regularPath.slice(0, -1) + indexSuffix
}
}
}
}
26 changes: 26 additions & 0 deletions packages/@vuepress/plugin-clean-urls/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@vuepress/plugin-clean-urls",
"version": "1.0.0-alpha.39",
"description": "clean urls plugin for vuepress",
"main": "index.js",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vuepress.git",
"directory": "packages/@vuepress/plugin-clean-urls"
},
"keywords": [
"documentation",
"vue",
"vuepress",
"generator"
],
"author": "Shigma <1700011071@pku.edu.cn>",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/vuepress/issues"
},
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-clean-urls#readme"
}
1 change: 1 addition & 0 deletions packages/docs/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function getPluginSidebar (pluginTitle, pluginIntro, officialPluginTitle) {
'official/plugin-medium-zoom',
'official/plugin-back-to-top',
'official/plugin-register-components',
'official/plugin-clean-urls'
]
}
]
Expand Down
51 changes: 51 additions & 0 deletions packages/docs/docs/plugin/official/plugin-clean-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: clean-urls
metaTitle: A plugin of automatically generating clean urls | VuePress
---

# [@vuepress/plugin-clean-urls](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-clean-urls)

> A plugin of automatically generating clean urls
## Install

```bash
yarn add -D @vuepress/plugin-clean-urls
# OR npm install -D @vuepress/plugin-clean-urls
```

## Usage

```javascript
module.exports = {
plugins: ['@vuepress/clean-urls']
}
```

## Options

### normalSuffix

- Type: `string`
- Default: `''`

The suffix for normal pages. For example, `foo/bar.md` will become:

- `foo/bar.html` by default (without this plugin)
- `foo/bar/` (with `normalSuffix` set to `'/'`)
- `foo/bar` (with `normalSuffix` set to `''`)

### indexSuffix

- Type: `string`
- Default: `'/'`

The suffix for index pages. For example, `foo/index.md` will become:

- `foo/` by default (without this plugin)
- `foo` (with `indexSuffix` set to `''`)
- `foo/index.html` (with `indexSuffix` set to `'/index.html'`)

::: tip
An index page is a page with a file name of index.md or readme.md (case insensitive).
:::
51 changes: 51 additions & 0 deletions packages/docs/docs/zh/plugin/official/plugin-clean-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: clean-urls
metaTitle: 自动生成简洁链接的插件 | VuePress
---

# [@vuepress/plugin-clean-urls](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-clean-urls)

> 自动生成简洁链接的插件
## 安装

```bash
yarn add -D @vuepress/plugin-clean-urls
# OR npm install -D @vuepress/plugin-clean-urls
```

## 使用

```javascript
module.exports = {
plugins: ['@vuepress/clean-urls']
}
```

## 选项

### normalSuffix

- 类型: `string`
- 默认值: `''`

普通页面的链接后缀。举个例子,`foo/bar.md` 会自动变成:

- `foo/bar.html` 在默认情况下(未安装本插件时)
- `foo/bar/`(当 `normalSuffix` 被设为 `'/'` 时)
- `foo/bar`(当 `normalSuffix` 被设为 `''` 时)

### indexSuffix

- 类型: `string`
- 默认值: `'/'`

索引页面的链接后缀。举个例子,`foo/index.md` 会自动变成:

- `foo/` 在默认情况下(未安装本插件时)
- `foo`(当 `indexSuffix` 被设为 `''` 时)
- `foo/index.html`(当 `indexSuffix` 被设为 `'/index.html'` 时)

::: tip
索引页面是指文件名为 index.md 或者 readme.md 的页面(不区分大小写)。
:::

0 comments on commit 40b3da8

Please sign in to comment.