Skip to content

Commit 9c0bd9e

Browse files
authored
feat: custom layout (#96)
* feat: custom layout * test: add test case * docs * test: adapt to latest testsuite
1 parent 67d7923 commit 9c0bd9e

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ index_generator:
2424
per_page: 10
2525
order_by: -date
2626
pagination_dir: page
27+
layout: ["index", "archive"]
2728
```
2829
2930
- **path**: Root path for your blog's index page.
@@ -36,6 +37,8 @@ index_generator:
3637
- **pagination_dir**: URL format.
3738
- default: `page`
3839
- e.g. set `awesome-page` makes the URL ends with `awesome-page/<page number>` for second page and beyond.
40+
- **layout**: custom layout.
41+
- defalut: `["index", "archive"]`
3942

4043
## Usage
4144

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
hexo.config.index_generator = Object.assign({
66
per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
7-
order_by: '-date'
7+
order_by: '-date',
8+
layout: ['index', 'archive']
89
}, hexo.config.index_generator);
910

1011
hexo.extend.generator.register('index', require('./lib/generator'));

lib/generator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function(locals) {
1313

1414
return pagination(path, posts, {
1515
perPage: config.index_generator.per_page,
16-
layout: ['index', 'archive'],
16+
layout: config.index_generator.layout || ['index', 'archive'],
1717
format: paginationDir + '/%d/',
1818
data: {
1919
__index: true

test/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,17 @@ describe('Index generator', () => {
148148
result[2].path.should.eql('yoyo/3/');
149149

150150
});
151+
152+
it('custom layout', () => {
153+
const custom_layout = ['custom', 'archive', 'index'];
154+
hexo.config.index_generator.layout = [...custom_layout];
155+
156+
const result = generator(locals);
157+
158+
result.forEach(res => {
159+
res.layout.should.eql(custom_layout);
160+
});
161+
162+
});
163+
151164
});

0 commit comments

Comments
 (0)