From 62364d1d11b870b45b486b6c7c9b4f385c045b1c Mon Sep 17 00:00:00 2001 From: joyzhao Date: Thu, 19 Jun 2025 18:31:45 +0800 Subject: [PATCH] feat(ui): improve empty state for taxonomy pages Add visual indicators and back-to-blog links for empty categories, tags, and search results --- src/components/blog/CategoryCard.astro | 31 +++++++++++++++++------ src/components/blog/TagCard.astro | 35 ++++++++++++++++++-------- src/layouts/TaxonomyPageLayout.astro | 15 ++++++++++- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/components/blog/CategoryCard.astro b/src/components/blog/CategoryCard.astro index 0e2e1b0..c1fb0f4 100644 --- a/src/components/blog/CategoryCard.astro +++ b/src/components/blog/CategoryCard.astro @@ -48,14 +48,29 @@ const title = titles[lang] || titles[defaultLang]; {title}
- {categories.map((cat) => { - const categoryId = categoryMap.get(cat) || cat.toLowerCase(); - return ( - - {cat} + {categories.length > 0 ? ( + categories.map((cat) => { + const categoryId = categoryMap.get(cat) || cat.toLowerCase(); + return ( + + {cat} + + ); + }) + ) : ( +
+ + + +

{lang === 'zh' ? '暂无分类' : 'No categories yet'}

+ + + + + {lang === 'zh' ? '返回博客列表' : 'Back to blog list'} - ); - })} +
+ )
\ No newline at end of file diff --git a/src/components/blog/TagCard.astro b/src/components/blog/TagCard.astro index 503cd64..b6a43d2 100644 --- a/src/components/blog/TagCard.astro +++ b/src/components/blog/TagCard.astro @@ -48,16 +48,31 @@ const title = titles[lang] || titles[defaultLang]; {title}
- {tags.map((tagItem) => { - const tagName = tagItem.slice(2); // 去掉 '# ' 前缀 - const tagId = tagMap.get(tagName) || tagName.toLowerCase(); - const isCurrentTag = tagId === currentTag.toLowerCase(); - return ( - - {tagItem} + {tags.length > 0 ? ( + tags.map((tagItem) => { + const tagName = tagItem.slice(2); // 去掉 '# ' 前缀 + const tagId = tagMap.get(tagName) || tagName.toLowerCase(); + const isCurrentTag = tagId === currentTag.toLowerCase(); + return ( + + {tagItem} + + ); + }) + ) : ( +
+ + + +

{lang === 'zh' ? '暂无标签' : 'No tags yet'}

+ + + + + {lang === 'zh' ? '返回博客列表' : 'Back to blog list'} - ); - })} +
+ )}
\ No newline at end of file diff --git a/src/layouts/TaxonomyPageLayout.astro b/src/layouts/TaxonomyPageLayout.astro index 2f6820b..cbfde71 100644 --- a/src/layouts/TaxonomyPageLayout.astro +++ b/src/layouts/TaxonomyPageLayout.astro @@ -86,8 +86,21 @@ const localizedText = getLocalizedText(); {posts.length > 0 ? ( ) : ( -
+
+ + {taxonomyType === 'category' ? ( + + ) : ( + + )} +

{localizedText.noResults}

+ + + + + {lang === 'zh' ? '返回博客列表' : 'Back to blog list'} +
)}