first commit
This commit is contained in:
7
node_modules/hexo-pagination/LICENSE
generated
vendored
Normal file
7
node_modules/hexo-pagination/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2014 Tommy Chen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
59
node_modules/hexo-pagination/README.md
generated
vendored
Normal file
59
node_modules/hexo-pagination/README.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# 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 |
|
||||
|
||||
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/
|
||||
78
node_modules/hexo-pagination/lib/pagination.js
generated
vendored
Normal file
78
node_modules/hexo-pagination/lib/pagination.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
|
||||
const { format } = require('util');
|
||||
|
||||
function pagination(base, posts, options = {}) {
|
||||
if (typeof base !== 'string') throw new TypeError('base must be a string!');
|
||||
if (!posts) throw new TypeError('posts is required!');
|
||||
|
||||
if (base && !base.endsWith('/')) base += '/';
|
||||
|
||||
const { length } = posts;
|
||||
|
||||
const { format: _format, layout, data, perPage } = Object.assign({
|
||||
format: 'page/%d/',
|
||||
layout: ['archive', 'index'],
|
||||
data: {},
|
||||
perPage: 10
|
||||
}, options);
|
||||
|
||||
const total = perPage ? Math.ceil(length / perPage) : 1;
|
||||
const result = [];
|
||||
const urlCache = new Map();
|
||||
|
||||
function formatURL(i) {
|
||||
if (urlCache.has(i)) return urlCache.get(i);
|
||||
|
||||
const url = i > 1 ? base + format(_format, i) : base;
|
||||
urlCache.set(i, url);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
function makeData(i) {
|
||||
const data = {
|
||||
base,
|
||||
total,
|
||||
current: i,
|
||||
current_url: formatURL(i),
|
||||
posts: perPage ? posts.slice(perPage * (i - 1), perPage * i) : posts,
|
||||
prev: 0,
|
||||
prev_link: '',
|
||||
next: 0,
|
||||
next_link: ''
|
||||
};
|
||||
|
||||
if (i > 1) {
|
||||
data.prev = i - 1;
|
||||
data.prev_link = formatURL(data.prev);
|
||||
}
|
||||
|
||||
if (i < total) {
|
||||
data.next = i + 1;
|
||||
data.next_link = formatURL(data.next);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
if (perPage) {
|
||||
for (let i = 1; i <= total; i++) {
|
||||
result.push({
|
||||
path: formatURL(i),
|
||||
layout,
|
||||
data: Object.assign(makeData(i), data)
|
||||
});
|
||||
}
|
||||
} else {
|
||||
result.push({
|
||||
path: base,
|
||||
layout,
|
||||
data: Object.assign(makeData(1), data)
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = pagination;
|
||||
36
node_modules/hexo-pagination/package.json
generated
vendored
Normal file
36
node_modules/hexo-pagination/package.json
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "hexo-pagination",
|
||||
"version": "3.0.0",
|
||||
"description": "Pagination utilities for Hexo generator plugins.",
|
||||
"main": "lib/pagination",
|
||||
"scripts": {
|
||||
"eslint": "eslint .",
|
||||
"test": "mocha test/index.js",
|
||||
"test-cov": "c8 --reporter=lcovonly npm run test"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"repository": "hexojs/hexo-pagination",
|
||||
"homepage": "https://hexo.io/",
|
||||
"keywords": [
|
||||
"hexo",
|
||||
"pagination",
|
||||
"util"
|
||||
],
|
||||
"author": "Tommy Chen <tommy351@gmail.com> (http://zespia.tw)",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-hexo": "^5.0.0",
|
||||
"mocha": "^10.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user