mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-09 05:16:23 +10:00
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
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
__tests__
|
||||
__mocks__
|
||||
.temp
|
||||
@@ -1,5 +0,0 @@
|
||||
# @vuepress/plugin-pagination
|
||||
|
||||
> pagination plugin for vuepress
|
||||
|
||||
See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-pagination.html).
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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)}`
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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 <chl814@foxmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/vuepress/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-pagination#readme"
|
||||
}
|
||||
@@ -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
|
||||
})
|
||||
```
|
||||
@@ -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
|
||||
})
|
||||
```
|
||||
Reference in New Issue
Block a user