Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom layout #96

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,6 +37,8 @@ index_generator:
- **pagination_dir**: URL format.
- default: `page`
- e.g. set `awesome-page` makes the URL ends with `awesome-page/<page number>` for second page and beyond.
- **layout**: custom layout.
- defalut: `["index", "archive"]`

## Usage

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
2 changes: 1 addition & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});