https://github.com/hexojs/hexo-pagination
Pagination utilities for Hexo generator plugins.
https://github.com/hexojs/hexo-pagination
hexo
Last synced: 3 months ago
JSON representation
Pagination utilities for Hexo generator plugins.
- Host: GitHub
- URL: https://github.com/hexojs/hexo-pagination
- Owner: hexojs
- License: mit
- Created: 2014-12-26T03:45:54.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-04T22:53:57.000Z (over 1 year ago)
- Last Synced: 2025-06-08T16:09:47.699Z (7 months ago)
- Topics: hexo
- Language: JavaScript
- Homepage:
- Size: 292 KB
- Stars: 23
- Watchers: 13
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-pagination
[](https://github.com/hexojs/hexo-pagination/actions?query=workflow%3ATester)
[](https://www.npmjs.com/package/hexo-pagination)
[](https://coveralls.io/r/hexojs/hexo-pagination?branch=master)
Pagination utilities for [Hexo] generator plugins.
## Installation
```bash
$ npm install hexo-pagination --save
```
## Usage
### pagination(base, posts, [options])
| Option | Description | Default |
| ---------------- | ----------------------------------------------- | ---------------------- |
| `perPage` | Posts displayed per page | `10` |
| `format` | URL format | `page/%d/` |
| `layout` | Layout. This value can be a string or an array. | `['archive', 'index']` |
| `data` | Extra data | `{}` |
| `explicitPaging` | Number the first page. e.g. `page/1/index.html` | `false` |
For example:
```js
var pagination = require("hexo-pagination");
pagination("/tags/hexo", [], {
perPage: 10,
format: "page/%d/",
layout: ["archive", "index"],
data: {
tag: "hexo",
},
});
```
This function returns an array containing objects with 3 properties: `path`, `layout`, `data`.
| Data | Description |
| ------------- | ------------------------------------------------- |
| `base` | Base URL |
| `total` | Total pages |
| `current` | Current page number |
| `current_url` | Path of the current page (which equals to `path`) |
| `posts` | The slice of posts for the current page |
| `prev` | Previous page number |
| `prev_link` | The path to the previous page |
| `next` | Next page number |
| `next_link` | The path to the next page |
## License
MIT
[Hexo]: https://hexo.io/