提交 37221926 编写于 作者: U ULIVZ

chore: deprecated @vuepress/plugin-pagination

BREAKING CHANGE: Function of this plugin has been integrated in the fresh official blog plugin:
https://github.com/ulivz/vuepress-plugin-blog
上级 c22c9411
# @vuepress/plugin-pagination
> pagination plugin for vuepress
See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-pagination.html).
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
}
}
})
}
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)}`
}
}
})
{
"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 <chl814@foxmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/vuepress/issues"
},
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-pagination#readme"
}
---
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
})
```
---
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
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册