diff --git a/packages/@vuepress/plugin-pagination/.npmignore b/packages/@vuepress/plugin-pagination/.npmignore deleted file mode 100644 index 13c38ea313..0000000000 --- a/packages/@vuepress/plugin-pagination/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -__tests__ -__mocks__ -.temp diff --git a/packages/@vuepress/plugin-pagination/README.md b/packages/@vuepress/plugin-pagination/README.md deleted file mode 100644 index 02746bc492..0000000000 --- a/packages/@vuepress/plugin-pagination/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @vuepress/plugin-pagination - -> pagination plugin for vuepress - -See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-pagination.html). diff --git a/packages/@vuepress/plugin-pagination/enhanceAppFile.js b/packages/@vuepress/plugin-pagination/enhanceAppFile.js deleted file mode 100644 index 20bf67ed06..0000000000 --- a/packages/@vuepress/plugin-pagination/enhanceAppFile.js +++ /dev/null @@ -1,71 +0,0 @@ -import paginationMeta from '@dynamic/pagination' - -class Pagination { - constructor (pagination, { pages, route }) { - let { postsFilter, postsSorter } = pagination - - /* eslint-disable no-eval */ - postsFilter = eval(postsFilter) - postsSorter = eval(postsSorter) - - const { path } = route - const { paginationPages } = pagination - - paginationPages.forEach((page, index) => { - if (page.path === path) { - this.paginationIndex = index - } - }) - - if (!this.paginationIndex) { - this.paginationIndex = 0 - } - - this._paginationPages = paginationPages - this._currentPage = paginationPages[this.paginationIndex] - this._posts = pages.filter(postsFilter).sort(postsSorter) - } - - get length () { - return this._paginationPages.length - } - - get posts () { - const [start, end] = this._currentPage.interval - return this._posts.slice(start, end + 1) - } - - get hasPrev () { - return this.paginationIndex !== 0 - } - - get prevLink () { - if (this.hasPrev) { - return this._paginationPages[this.paginationIndex - 1].path - } - } - - get hasNext () { - return this.paginationIndex !== this.length - 1 - } - - get nextLink () { - if (this.hasNext) { - return this._paginationPages[this.paginationIndex + 1].path - } - } -} - -export default ({ Vue }) => { - Vue.mixin({ - computed: { - $pagination () { - const { pages } = this.$site - const pagination = new Pagination(paginationMeta, { - pages, route: this.$route - }) - return pagination - } - } - }) -} diff --git a/packages/@vuepress/plugin-pagination/index.js b/packages/@vuepress/plugin-pagination/index.js deleted file mode 100644 index ba27c01b88..0000000000 --- a/packages/@vuepress/plugin-pagination/index.js +++ /dev/null @@ -1,69 +0,0 @@ -const { path } = require('@vuepress/shared-utils') - -function getIntervallers (max, interval) { - const count = max % interval === 0 ? Math.floor(max / interval) : Math.floor(max / interval) + 1 - const arr = [...Array(count)] - return arr.map((v, index) => { - const start = index * interval - const end = (index + 1) * interval - return [start, end > max ? max : end] - }) -} - -module.exports = (options, ctx) => ({ - enhanceAppFiles: [ - path.resolve(__dirname, 'enhanceAppFile.js') - ], - - ready () { - let { postsFilter, postsSorter } = options - postsFilter = postsFilter || (({ type }) => type === 'post') - postsSorter = postsSorter || ((prev, next) => { - const prevTime = new Date(prev.frontmatter.date).getTime() - const nextTime = new Date(next.frontmatter.date).getTime() - return prevTime - nextTime > 0 ? -1 : 1 - }) - - const { pages } = ctx - const posts = pages.filter(postsFilter) - const { - perPagePosts = 10, - paginationDir = 'page', - firstPagePath = '/', - layout = 'Layout' - } = options - - const intervallers = getIntervallers(posts.length, perPagePosts) - const pagination = { - paginationPages: intervallers.map((interval, index) => { - const path = index === 0 - ? firstPagePath - : `/${paginationDir}/${index + 1}/` - return { path, interval } - }), - postsFilter: postsFilter.toString(), - postsSorter: postsSorter.toString() - } - - ctx.pagination = pagination - pagination.paginationPages.forEach(({ path }, index) => { - if (path === '/') { - return - } - ctx.addPage({ - permalink: path, - frontmatter: { - layout, - title: `Page ${index + 1}` - } - }) - }) - }, - - async clientDynamicModules () { - return { - name: 'pagination.js', - content: `export default ${JSON.stringify(ctx.pagination, null, 2)}` - } - } -}) diff --git a/packages/@vuepress/plugin-pagination/package.json b/packages/@vuepress/plugin-pagination/package.json deleted file mode 100644 index e6bdbe8837..0000000000 --- a/packages/@vuepress/plugin-pagination/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@vuepress/plugin-pagination", - "version": "1.0.0-alpha.50", - "description": "pagination plugin for vuepress", - "main": "index.js", - "publishConfig": { - "access": "public" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/vuejs/vuepress.git", - "directory": "packages/@vuepress/plugin-pagination" - }, - "keywords": [ - "documentation", - "vue", - "vuepress", - "generator" - ], - "author": "ULIVZ ", - "license": "MIT", - "bugs": { - "url": "https://github.com/vuejs/vuepress/issues" - }, - "homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-pagination#readme" -} diff --git a/packages/docs/docs/plugin/official/plugin-pagination.md b/packages/docs/docs/plugin/official/plugin-pagination.md deleted file mode 100644 index 22a4c35d07..0000000000 --- a/packages/docs/docs/plugin/official/plugin-pagination.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: pagination -metaTitle: Pagination Plugin | VuePress ---- - -# [@vuepress/plugin-pagination](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-pagination) - -> pagination plugin - -## Install - -```bash -yarn add -D @vuepress/plugin-pagination@next -# OR npm install -D @vuepress/plugin-pagination@next -``` - -## Usage - -```javascript -module.exports = { - plugins: ['@vuepress/pagination'] -} -``` - -## Options - -### postsFilter - -- Type: `function` -- Default: - -```js -(({ type }) => type === 'post')` -``` - -### postsSorter - -- Type: `function` -- Default: - -```js -((prev, next) => { - const prevTime = new Date(prev.frontmatter.date).getTime() - const nextTime = new Date(next.frontmatter.date).getTime() - return prevTime - nextTime > 0 ? -1 : 1 -}) -``` diff --git a/packages/docs/docs/zh/plugin/official/plugin-pagination.md b/packages/docs/docs/zh/plugin/official/plugin-pagination.md deleted file mode 100644 index 1adb15507d..0000000000 --- a/packages/docs/docs/zh/plugin/official/plugin-pagination.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: pagination -metaTitle: Pagination 插件 | VuePress ---- - -# [@vuepress/plugin-pagination](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-pagination) - -> 分页器插件 - -## 安装 - -```bash -yarn add -D @vuepress/plugin-pagination@next -# OR npm install -D @vuepress/plugin-pagination@next -``` - -## 使用 - -```javascript -module.exports = { - plugins: ['@vuepress/pagination'] -} -``` - -## 选项 - -### postsFilter - -- 类型: `function` -- 默认值: - -```js -(({ type }) => type === 'post')` -``` - -### postsSorter - -- 类型: `function` -- 默认值: - -```js -((prev, next) => { - const prevTime = new Date(prev.frontmatter.date).getTime() - const nextTime = new Date(next.frontmatter.date).getTime() - return prevTime - nextTime > 0 ? -1 : 1 -}) -```