From 149e73faa3f16ede991bd4160d9e6cbcbed58514 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 e7bb50646f..28c1542011 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -473,9 +473,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 = {};