diff --git a/src/components/Archive.astro b/src/components/Archive.astro index 2f074d0..0a8a58e 100644 --- a/src/components/Archive.astro +++ b/src/components/Archive.astro @@ -7,11 +7,21 @@ interface Props { lang?: 'en' | 'zh'; /** Filter bar + chips. Off on tag/collection pages, where the set is already narrow. */ chrome?: boolean; + /** + * Posts the tag-chip strip is built from. Defaults to `posts`, which is right on + * the archive; a tag page passes the whole language collection so its strip is the + * same site-wide topic menu as /posts/ (the chips navigate, so their counts must be + * site-wide or they would lie). Category chips and the row filter stay scoped to + * `posts`, so their counts always match the rows actually on the page. + */ + chipPosts?: CollectionEntry<'posts'>[]; + /** On a tag page, the tag being viewed — its chip is marked active instead of looking clickable-to-self. */ + activeTag?: string; } -const { posts, lang = 'en', chrome = true } = Astro.props; +const { posts, lang = 'en', chrome = true, chipPosts = posts, activeTag } = Astro.props; const isZh = lang === 'zh'; -const counts = tagCounts(posts); +const counts = tagCounts(chipPosts); const years = [...new Set(posts.map((p) => p.data.pubDate.getUTCFullYear()))].sort((a, b) => b - a); const categories = [...new Set(posts.map((p) => p.data.category))] .map((c) => ({ name: c, n: posts.filter((p) => p.data.category === c).length })) @@ -56,7 +66,11 @@ const labels = isZh
> diff --git a/src/pages/tags/[tag].astro b/src/pages/tags/[tag].astro index 4e18d02..70bebec 100644 --- a/src/pages/tags/[tag].astro +++ b/src/pages/tags/[tag].astro @@ -16,11 +16,16 @@ export async function getStaticPaths() { const counts = tagCounts(posts); return tagPageNames(posts).map((tag) => ({ params: { tag }, - props: { tag, n: counts.get(tag) ?? 0, posts: posts.filter((p) => p.data.tags.includes(tag)) }, + props: { + tag, + n: counts.get(tag) ?? 0, + posts: posts.filter((p) => p.data.tags.includes(tag)), + all: posts, + }, })); } -const { tag, posts } = Astro.props as { tag: string; posts: any[] }; +const { tag, posts, all } = Astro.props as { tag: string; posts: any[]; all: any[] }; ---