Skip to content

Commit fc6418e

Browse files
committed
feat: 重构内容列表页标签展示与筛选交互
在 PageIntro 中展示当前列表聚合标签 在博客 tag 详情页隐藏 intro 标签行 将筛选功能整合到 ContentLayoutGrid 顶栏 支持按关键字、作者、年份和标签多选筛选文章 将标签筛选改为或关系并修复下拉层被容器裁切的问题
1 parent c225655 commit fc6418e

4 files changed

Lines changed: 417 additions & 15 deletions

File tree

src/components/content/ContentIndexSection.astro

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ interface Props {
1313
entries: AnyEntry[];
1414
emptyText: string;
1515
hrefPrefix: "/blog/" | "/news/" | "/projects/";
16+
showIntroTags?: boolean;
1617
}
1718
18-
const { title, description, eyebrow, entries, emptyText, hrefPrefix } =
19+
const {
20+
title,
21+
description,
22+
eyebrow,
23+
entries,
24+
emptyText,
25+
hrefPrefix,
26+
showIntroTags = true,
27+
} =
1928
Astro.props;
2029
2130
const storageKeyMap: Record<string, string> = {
@@ -31,16 +40,36 @@ const items = entries.map((entry) => ({
3140
title: entry.data.title,
3241
description: entry.data.description,
3342
dateText: entry.data.date.toLocaleDateString("zh-CN"),
43+
dateValue: entry.data.date.toISOString(),
3444
meta: entry.data.author,
45+
author: entry.data.author,
46+
tags: entry.data.tags,
3547
}));
48+
49+
const introTags = [...new Set(entries.flatMap((entry) => entry.data.tags))]
50+
.sort((a, b) => a.localeCompare(b, "zh-CN"))
51+
.map((tag) => ({
52+
label: tag,
53+
href: hrefPrefix === "/blog/" ? `/blog/tags/${encodeURIComponent(tag)}/` : undefined,
54+
}));
3655
---
3756

3857
<section class="section-shell">
3958
<div class="container-shell">
40-
<PageIntro title={title} description={description} eyebrow={eyebrow} />
59+
<PageIntro
60+
title={title}
61+
description={description}
62+
eyebrow={eyebrow}
63+
tags={showIntroTags ? introTags : []}
64+
/>
4165
{
4266
entries.length > 0 ? (
43-
<ContentLayoutGrid client:load items={items} storageKey={storageKey} />
67+
<ContentLayoutGrid
68+
client:load
69+
items={items}
70+
storageKey={storageKey}
71+
emptyText={emptyText}
72+
/>
4473
) : (
4574
<SurfaceCard class="p-4 text-ink-500">{emptyText}</SurfaceCard>
4675
)

0 commit comments

Comments
 (0)