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

为 post 的 Front-matter 中添加 archive 选项用于决定 post 是否在首页展示(默认仍为展示) #869

Merged
merged 1 commit into from
Mar 3, 2023
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
2 changes: 2 additions & 0 deletions scripts/filters/post-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ hexo.extend.filter.register('before_generate', function() {
});
const hidePosts = allPosts.filter(post => post.hide);
const normalPosts = allPosts.filter(post => !post.hide);
const indexPost = allPosts.filter(post => !post.archive)

this.locals.set('all_posts', allPosts);
this.locals.set('hide_posts', hidePosts);
this.locals.set('posts', normalPosts);
this.locals.set('index_posts', indexPost);
});

const original_post_generator = hexo.extend.generator.get('post');
Expand Down
22 changes: 22 additions & 0 deletions scripts/generators/index-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const pagination = require('hexo-pagination');

module.exports = function(locals) {
const config = this.config;
const posts = locals.index_posts.sort(config.index_generator.order_by);

posts.data.sort((a, b) => (b.sticky || 0) - (a.sticky || 0));

const paginationDir = config.pagination_dir || 'page';
const path = config.index_generator.path || '';

return pagination(path, posts, {
perPage: config.index_generator.per_page,
layout: 'index',
format: paginationDir + '/%d/',
data: {
__index: true
}
});
};
3 changes: 3 additions & 0 deletions scripts/generators/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ hexo.extend.generator.register('_links', function(locals) {
};
}
});

// generate index page
hexo.extend.generator.register('index', require('./index-generator'));