diff --git a/packages/@vuepress/plugin-clean-urls/.npmignore b/packages/@vuepress/plugin-clean-urls/.npmignore new file mode 100644 index 0000000000..13c38ea313 --- /dev/null +++ b/packages/@vuepress/plugin-clean-urls/.npmignore @@ -0,0 +1,3 @@ +__tests__ +__mocks__ +.temp diff --git a/packages/@vuepress/plugin-clean-urls/README.md b/packages/@vuepress/plugin-clean-urls/README.md new file mode 100644 index 0000000000..f9bfc3dfbb --- /dev/null +++ b/packages/@vuepress/plugin-clean-urls/README.md @@ -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). diff --git a/packages/@vuepress/plugin-clean-urls/index.js b/packages/@vuepress/plugin-clean-urls/index.js new file mode 100644 index 0000000000..d09d0754e5 --- /dev/null +++ b/packages/@vuepress/plugin-clean-urls/index.js @@ -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 + } + } + } +} diff --git a/packages/@vuepress/plugin-clean-urls/package.json b/packages/@vuepress/plugin-clean-urls/package.json new file mode 100644 index 0000000000..f678b34391 --- /dev/null +++ b/packages/@vuepress/plugin-clean-urls/package.json @@ -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" +} diff --git a/packages/docs/docs/.vuepress/config.js b/packages/docs/docs/.vuepress/config.js index 624e35d2d8..710c2313c4 100644 --- a/packages/docs/docs/.vuepress/config.js +++ b/packages/docs/docs/.vuepress/config.js @@ -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' ] } ] diff --git a/packages/docs/docs/plugin/official/plugin-clean-urls.md b/packages/docs/docs/plugin/official/plugin-clean-urls.md new file mode 100644 index 0000000000..6f801be040 --- /dev/null +++ b/packages/docs/docs/plugin/official/plugin-clean-urls.md @@ -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). +::: diff --git a/packages/docs/docs/zh/plugin/official/plugin-clean-urls.md b/packages/docs/docs/zh/plugin/official/plugin-clean-urls.md new file mode 100644 index 0000000000..e986d188ef --- /dev/null +++ b/packages/docs/docs/zh/plugin/official/plugin-clean-urls.md @@ -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 的页面(不区分大小写)。 +:::