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 3 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ archive_generator:
monthly: true
daily: false
order_by: -date
explicit_paging: false
overwrite_latest: false
verbose: false
```

- **enabled**: The default value is **true**, set to **false** if you do not want to enable the plugin
Expand All @@ -30,6 +33,9 @@ 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`)
- **overwrite_latest**: Set the latest page. (`latest/index.html` in place of `page/N/index.html`)
- **verbose**: verbose output. (Output all generated routes)

## License

Expand Down
17 changes: 15 additions & 2 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ 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: (config.archive_generator.explicit_paging || config.archive_generator.overwrite_latest || false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think overwrite_latest should not be added here, as this may confuse users. It makes it ambiguous whether to enable explicit_paging

data: options
}));
});

if ((config.archive_generator.overwrite_latest || false) && pages.length > 0) {
const lastPage = pages[pages.length - 1];
lastPage.path = lastPage.path.replace(/\/page\/\d+\/?$/, '/latest/');
Copy link
Member

@uiolee uiolee Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this destroys the unambiguity of explicit_paging.
I think adding an additional path will be better than overwriting it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not modifying if there is a single page. The objective is to have it changed even if there is 1 page. For the users is transparent, it the flag is set then all the pages (even if there is only one) end with /latest in the path

for example /tag/mytag/1 is renamed to /tag/mytag/latest and properly linked if you create a page with all the tags.

the overwrite is made on purpose so that is not duplicating pages (the static generator create the page), as the last page (with number) is never used. You can see the result in my blog.

}

if (config.archive_generator.verbose || false) {
pages.forEach(page => {
console.log(`Generated archive route: ${page.path}`);
});
}
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-generator-archive",
"version": "2.0.0",
"version": "2.1.0",
azimonti marked this conversation as resolved.
Show resolved Hide resolved
"description": "Archive generator for Hexo.",
"main": "index",
"scripts": {
Expand Down 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
Loading