diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index c248b7b675..5a0c568273 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -294,9 +294,15 @@ class Hexo extends EventEmitter { 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 = {};