From 818fa988a79b144337976b9557fe50e3d8fd4e93 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Fri, 19 Apr 2024 00:31:48 +0800 Subject: [PATCH] fix: pagination_dir setting --- lib/generator.js | 2 +- test/index.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 1519d02..bdfcad4 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -8,7 +8,7 @@ module.exports = function(locals) { posts.data.sort((a, b) => (b.sticky || 0) - (a.sticky || 0)); - const paginationDir = config.pagination_dir || 'page'; + const paginationDir = config.index_generator.pagination_dir || config.pagination_dir || 'page'; const path = config.index_generator.path || ''; return pagination(path, posts, { diff --git a/test/index.js b/test/index.js index 15bf534..e029211 100644 --- a/test/index.js +++ b/test/index.js @@ -127,7 +127,7 @@ describe('Index generator', () => { }); }); - it('custom pagination_dir', () => { + it('custom pagination_dir - global setting', () => { hexo.config.index_generator.per_page = 1; hexo.config.pagination_dir = 'yo'; @@ -141,4 +141,20 @@ describe('Index generator', () => { hexo.config.index_generator.per_page = 10; hexo.config.pagination_dir = 'page'; }); + + it('custom pagination_dir - plugin setting', () => { + hexo.config.index_generator.per_page = 1; + hexo.config.index_generator.pagination_dir = 'yoyo'; + + const result = generator(locals); + + result[0].path.should.eql(''); + result[1].path.should.eql('yoyo/2/'); + result[2].path.should.eql('yoyo/3/'); + + // Restore config + hexo.config.index_generator.per_page = 10; + hexo.config.index_generator.pagination_dir = 'page'; + }); + });