diff --git a/README.md b/README.md index 6e31363..49acdb5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ index_generator: per_page: 10 order_by: -date pagination_dir: page + layout: ["index", "archive"] ``` - **path**: Root path for your blog's index page. @@ -36,6 +37,8 @@ index_generator: - **pagination_dir**: URL format. - default: `page` - e.g. set `awesome-page` makes the URL ends with `awesome-page/` for second page and beyond. +- **layout**: custom layout. + - defalut: `["index", "archive"]` ## Usage diff --git a/index.js b/index.js index 328aaab..64db16b 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,8 @@ hexo.config.index_generator = Object.assign({ per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page, - order_by: '-date' + order_by: '-date', + layout: ['index', 'archive'] }, hexo.config.index_generator); hexo.extend.generator.register('index', require('./lib/generator')); diff --git a/lib/generator.js b/lib/generator.js index bdfcad4..631bd5a 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -13,7 +13,7 @@ module.exports = function(locals) { return pagination(path, posts, { perPage: config.index_generator.per_page, - layout: ['index', 'archive'], + layout: config.index_generator.layout || ['index', 'archive'], format: paginationDir + '/%d/', data: { __index: true diff --git a/test/index.js b/test/index.js index a07c515..fceec59 100644 --- a/test/index.js +++ b/test/index.js @@ -149,4 +149,17 @@ describe('Index generator', () => { hexo.config.index_generator.per_page = 10; hexo.config.index_generator.pagination_dir = 'page'; }); + + it('custom layout', () => { + const custom_layout = ['custom', 'archive', 'index']; + hexo.config.index_generator.layout = [...custom_layout]; + + const result = generator(locals); + + result.forEach(res => { + res.layout.should.eql(custom_layout); + }); + + }); + });