From 59aeb879110f6fd35fd87e7655cbbbfd84e49201 Mon Sep 17 00:00:00 2001 From: Uiolee <22849383+uiolee@users.noreply.github.com> Date: Tue, 9 Jul 2024 06:47:09 +0800 Subject: [PATCH] fix: pagination_dir setting (#98) Signed-off-by: yoshinorin Co-authored-by: yoshinorin --- lib/generator.js | 2 +- test/index.js | 16 +++++++++++++++- 2 files changed, 16 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 8570e26..a07c515 100644 --- a/test/index.js +++ b/test/index.js @@ -123,7 +123,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'; @@ -135,4 +135,18 @@ describe('Index generator', () => { }); + 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'; + }); });