From 0fb3f8c17fc885f9afaab6b35f7744e4e9355d5a Mon Sep 17 00:00:00 2001 From: Marco Azimonti Date: Fri, 13 Dec 2024 20:14:21 +0900 Subject: [PATCH 1/3] added "explicit_paging" and "overwrite_latest" options --- README.md | 6 ++++++ lib/generator.js | 12 ++++++++++++ package.json | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2238e1a..bd612b2 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,18 @@ $ npm install hexo-generator-tag --save tag_generator: per_page: 10 order_by: -date + explicit_paging: false + overwrite_latest: false + verbose: false ``` - **per_page**: Posts displayed per page. (0 = disable pagination) - **order_by**: Posts order. (Order by date descending by default) - **enable_index_page**: Generate a `/[config.tag_dir]/index.html` page. - Support following template layout: `tag-index`, `tag`, `archive`, `index` +- **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 diff --git a/lib/generator.js b/lib/generator.js index 42b47d8..b7d61dd 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -18,11 +18,23 @@ module.exports = function(locals) { perPage: perPage, layout: ['tag', 'archive', 'index'], format: paginationDir + '/%d/', + explicitPaging: (config.tag_generator.explicit_paging || config.tag_generator.overwrite_latest || false), data: { tag: tag.name } }); + if ((config.tag_generator.overwrite_latest || false) && data.length > 0) { + const lastPage = data[data.length - 1]; + lastPage.path = lastPage.path.replace(/\/page\/\d+\/?$/, '/latest/'); + } + + if (config.tag_generator.verbose || false) { + data.forEach(page => { + console.log(`Generated tag route: ${page.path}`); + }); + } + return result.concat(data); }, []); diff --git a/package.json b/package.json index 96e905e..032a276 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-generator-tag", - "version": "2.0.0", + "version": "2.1.0", "description": "Tag generator for Hexo.", "main": "index", "scripts": { @@ -33,7 +33,7 @@ "mocha": "^10.0.0" }, "dependencies": { - "hexo-pagination": "3.0.0" + "hexo-pagination": "4.0.0" }, "engines": { "node": ">=14" From a301265803689e501b653f3924e1c8bfacc4a973 Mon Sep 17 00:00:00 2001 From: Marco Azimonti Date: Thu, 16 Jan 2025 19:54:17 +0900 Subject: [PATCH 2/3] moved the logic into hexo-pagination --- README.md | 2 +- lib/generator.js | 18 ++++++------------ package.json | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bd612b2..7e1f0a0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ tag_generator: - **enable_index_page**: Generate a `/[config.tag_dir]/index.html` page. - Support following template layout: `tag-index`, `tag`, `archive`, `index` - **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`) +- **overwrite_latest**: Set the latest page. (`latest/index.html` in place of `page/N/index.html`). If there is a single page it requires explicitPaging=true`. - **verbose**: verbose output. (Output all generated routes) ## License diff --git a/lib/generator.js b/lib/generator.js index b7d61dd..e7b2c79 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -7,6 +7,9 @@ module.exports = function(locals) { const perPage = config.tag_generator.per_page; const paginationDir = config.pagination_dir || 'page'; const orderBy = config.tag_generator.order_by || '-date'; + const explicitPaging = config.tag_generator.explicit_paging || false; + const overwriteLatest = config.tag_generator.overwrite_latest || false; + const verbose = config.tag_generator.verbose || false; const tags = locals.tags; let tagDir; @@ -18,23 +21,14 @@ module.exports = function(locals) { perPage: perPage, layout: ['tag', 'archive', 'index'], format: paginationDir + '/%d/', - explicitPaging: (config.tag_generator.explicit_paging || config.tag_generator.overwrite_latest || false), + explicitPaging: explicitPaging, + overwriteLatest: overwriteLatest, + verbose: verbose, data: { tag: tag.name } }); - if ((config.tag_generator.overwrite_latest || false) && data.length > 0) { - const lastPage = data[data.length - 1]; - lastPage.path = lastPage.path.replace(/\/page\/\d+\/?$/, '/latest/'); - } - - if (config.tag_generator.verbose || false) { - data.forEach(page => { - console.log(`Generated tag route: ${page.path}`); - }); - } - return result.concat(data); }, []); diff --git a/package.json b/package.json index 032a276..c952dd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-generator-tag", - "version": "2.1.0", + "version": "2.0.0", "description": "Tag generator for Hexo.", "main": "index", "scripts": { From 8e7640ad78ef38c78b9aef175b3d0d33905ded3f Mon Sep 17 00:00:00 2001 From: Marco Azimonti Date: Tue, 28 Jan 2025 22:10:09 +0900 Subject: [PATCH 3/3] changed option to rename_last and added localization --- README.md | 6 ++++-- lib/generator.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7e1f0a0..c104e1d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ tag_generator: per_page: 10 order_by: -date explicit_paging: false - overwrite_latest: false + rename_last: false + localized_last: 'last' verbose: false ``` @@ -28,7 +29,8 @@ tag_generator: - **enable_index_page**: Generate a `/[config.tag_dir]/index.html` page. - Support following template layout: `tag-index`, `tag`, `archive`, `index` - **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`). If there is a single page it requires explicitPaging=true`. +- **rename_last**: Set the latest page name. (`page/last/index.html` in place of `page/N/index.html`). If there is a single page it requires explicit_paging=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 diff --git a/lib/generator.js b/lib/generator.js index e7b2c79..324a67b 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -8,7 +8,8 @@ module.exports = function(locals) { const paginationDir = config.pagination_dir || 'page'; const orderBy = config.tag_generator.order_by || '-date'; const explicitPaging = config.tag_generator.explicit_paging || false; - const overwriteLatest = config.tag_generator.overwrite_latest || false; + const renameLast = config.tag_generator.rename_last || false; + const localizedLast = config.tag_generator.localized_last || 'last'; const verbose = config.tag_generator.verbose || false; const tags = locals.tags; let tagDir; @@ -22,7 +23,8 @@ module.exports = function(locals) { layout: ['tag', 'archive', 'index'], format: paginationDir + '/%d/', explicitPaging: explicitPaging, - overwriteLatest: overwriteLatest, + renameLast: renameLast, + localizedLast: localizedLast, verbose: verbose, data: { tag: tag.name