Skip to content

Commit

Permalink
feat: hide posts from index
Browse files Browse the repository at this point in the history
  • Loading branch information
muhac committed Nov 15, 2024
1 parent 83d121f commit 2064bd3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pagination = require('hexo-pagination');

module.exports = function(locals) {
const config = this.config;
const posts = locals.posts.sort(config.index_generator.order_by);
const posts = locals.posts.filter(post => !post.hidden).sort(config.index_generator.order_by);

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

Expand Down
5 changes: 3 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ describe('Index generator', () => {
before(() => hexo.init().then(() => Post.insert([
{source: 'foo', slug: 'foo', date: 1e8, order: 0},
{source: 'bar', slug: 'bar', date: 1e8 + 1, order: 10},
{source: 'baz', slug: 'baz', date: 1e8 - 1, order: 1}
{source: 'baz', slug: 'baz', date: 1e8 - 1, order: 1},
{source: 'qux', slug: 'qux', date: 1e8 - 8, order: 8, hidden: true}
])).then(data => {
posts = Post.sort('-date');
posts = Post.slice(0, -1).sort('-date');
locals = hexo.locals.toObject();
}));

Expand Down

0 comments on commit 2064bd3

Please sign in to comment.