diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 4060dc4228..065b7619d3 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -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 = {}; diff --git a/lib/plugins/helper/tagcloud.js b/lib/plugins/helper/tagcloud.js index 9fd5bda421..d4ad0e3c75 100644 --- a/lib/plugins/helper/tagcloud.js +++ b/lib/plugins/helper/tagcloud.js @@ -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);