From 51540b7ce5f2e043dd8ddd0db89475020d0c3fcb Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:56:05 +0800 Subject: [PATCH] fix(categories,tags): revert behavior of locals.tags and locals.categories --- lib/hexo/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 = {};