Skip to content

Commit

Permalink
refactor: ignore categories / tags with zero posts (hexojs#3624)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored and Thomas Parisot committed Jan 17, 2020
1 parent 82d89f3 commit c2dad09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ Hexo.prototype._bindLocals = function() {
return db.model('Page').find(query);
});

locals.set('categories', () => db.model('Category'));
locals.set('categories', () => {
// Ignore categories with zero posts
return db.model('Category').filter(category => category.length);
});

locals.set('tags', () => db.model('Tag'));
locals.set('tags', () => {
// Ignore tags with zero posts
return db.model('Tag').filter(tag => tag.length);
});

locals.set('data', () => {
const obj = {};
Expand Down
3 changes: 0 additions & 3 deletions lib/plugins/helper/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ function tagcloudHelper(tags, options) {
tags = tags.sort(orderby, order);
}

// Ignore tags with zero posts
tags = tags.filter(tag => tag.length);

// Limit the number of tags
if (options.amount) {
tags = tags.limit(options.amount);
Expand Down

0 comments on commit c2dad09

Please sign in to comment.