Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit paging #216

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ archive_generator:
monthly: true
daily: false
order_by: -date
explicit_paging: false
rename_last: false
localized_last: 'last'
verbose: false
```

- **enabled**: The default value is **true**, set to **false** if you do not want to enable the plugin
Expand All @@ -30,6 +34,10 @@ archive_generator:
- **monthly**: Generate monthly archive.
- **daily**: Generate daily archive.
- **order_by**: Posts order. (Order by date descending by default)
- **explicit_paging**: Explicit paging. (Number the first page. e.g. `page/1/index.html`)
- **rename_last**: Set the latest page. (`page/last/index.html` in place of `page/N/index.html`). If there is a single page it requires explicitPaging=true`.
- **localized_last**: Localize the last page name. (`page/最後/index.html` in place of `page/last/index.html`).
- **verbose**: verbose output. (Output all generated routes)

## License

Expand Down
14 changes: 12 additions & 2 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module.exports = function(locals) {
const paginationDir = config.pagination_dir || 'page';
const allPosts = locals.posts.sort(config.archive_generator.order_by || '-date');
const perPage = config.archive_generator.per_page;
const explicitPaging = config.archive_generator.explicit_paging || false;
const renameLast = config.archive_generator.rename_last || false;
const localizedLast = config.archive_generator.localized_last || 'last';
const verbose = config.archive_generator.verbose || false;
const result = [];

if (!allPosts.length) return;
Expand All @@ -20,12 +24,18 @@ module.exports = function(locals) {
function generate(path, posts, options = {}) {
options.archive = true;

result.push(...pagination(path, posts, {
const pages = pagination(path, posts, {
perPage,
layout: ['archive', 'index'],
format: paginationDir + '/%d/',
explicitPaging: explicitPaging,
renameLast: renameLast,
localizedLast: localizedLast,
verbose: verbose,
data: options
}));
});

result.push(...pages);
}

generate(archiveDir, allPosts);
Expand Down
45 changes: 34 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"mocha": "^10.0.0"
},
"dependencies": {
"hexo-pagination": "3.0.0"
"hexo-pagination": "4.0.0"
},
"engines": {
"node": ">=14"
Expand Down