From b6ebbcaa6cc65a2722d917570676fd00addb607e Mon Sep 17 00:00:00 2001 From: Uiolee <22849383+uiolee@users.noreply.github.com> Date: Sun, 14 Apr 2024 10:37:31 +0800 Subject: [PATCH] fix(categories,tags): revert behavior of locals.tags and locals.categories (#5388) --- 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 b1e32a2762..b9ca764dd4 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -386,9 +386,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 = {};