Skip to content

Commit 6a8c31e

Browse files
committed
feat: redesign tag filter and page to be more like tabs
1 parent 9061168 commit 6a8c31e

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

src/components/ui/TagFilter.astro

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
import TagList from "./TagList.astro";
3+
import { getCollection } from "astro:content";
4+
5+
interface Props {
6+
activeTag?: string;
7+
class?: string;
8+
}
9+
10+
const { activeTag, class: className = "" } = Astro.props;
11+
12+
const posts = (await getCollection("news", ({ data }) => !data.draft)).sort(
13+
(a, b) => b.data.date.getTime() - a.data.date.getTime(),
14+
);
15+
16+
const popularTags = posts
17+
.flatMap(({ data }) => data.tags)
18+
.reduce(
19+
(counts, tag) => counts.set(tag, (counts.get(tag) || 0) + 1),
20+
new Map<string, number>(),
21+
)
22+
.entries()
23+
.toArray()
24+
.sort(([, a], [, b]) => b - a)
25+
.map(([tag]) => tag);
26+
---
27+
28+
{
29+
popularTags.length > 0 && (
30+
<TagList
31+
tags={popularTags}
32+
showAll
33+
class={`gap-2 ${className}`}
34+
activeTag={activeTag}
35+
/>
36+
)
37+
}

src/pages/news/index.astro

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,13 @@ import ProseCard from "../../components/ui/ProseCard.astro";
44
import Card from "../../components/ui/Card.astro";
55
import Button from "../../components/ui/Button.astro";
66
import NewsCard from "../../components/NewsCard.astro";
7-
import TagList from "../../components/ui/TagList.astro";
7+
import TagFilter from "../../components/ui/TagFilter.astro";
88
import { getCollection } from "astro:content";
99
1010
const posts = (await getCollection("news", ({ data }) => !data.draft)).sort(
1111
(a, b) => b.data.date.getTime() - a.data.date.getTime(),
1212
);
1313
const [latestPost, ...remainingPosts] = posts;
14-
15-
const popularTags = posts
16-
.flatMap(({ data }) => data.tags)
17-
.reduce(
18-
(counts, tag) => counts.set(tag, (counts.get(tag) || 0) + 1),
19-
new Map<string, number>(),
20-
)
21-
.entries()
22-
.toArray()
23-
.sort(([, a], [, b]) => b - a)
24-
.slice(0, 8)
25-
.map(([tag]) => tag);
2614
---
2715

2816
<MainLayout
@@ -36,13 +24,7 @@ const popularTags = posts
3624
Launcher now supports viewing news directly in the Launcher by clicking
3725
the news icon at the bottom of the window.
3826
</p>
39-
40-
<!-- popular tags filter -->
41-
{
42-
popularTags.length > 0 && (
43-
<TagList tags={popularTags} showAll class="gap-2" />
44-
)
45-
}
27+
<TagFilter />
4628
</ProseCard>
4729

4830
<!-- featured latest post -->

src/pages/news/tag/[tag].astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ProseCard from "../../../components/ui/ProseCard.astro";
44
import Card from "../../../components/ui/Card.astro";
55
import NewsCard from "../../../components/NewsCard.astro";
66
import Breadcrumb from "../../../components/ui/Breadcrumb.astro";
7+
import TagFilter from "../../../components/ui/TagFilter.astro";
78
import { getCollection } from "astro:content";
89
910
export async function getStaticPaths() {
@@ -33,11 +34,13 @@ const filteredPosts = allPosts.filter(({ data }) => data.tags.includes(tag));
3334
description={`All news posts tagged with "${tag}"`}
3435
>
3536
<ProseCard>
36-
<Breadcrumb href="/news" text="News" class="mb-3" />
37-
<h1 class="heading-1 mb-4">Posts tagged "{tag}"</h1>
37+
<h1 class="heading-1 mb-6">News</h1>
3838
<p>
39-
{filteredPosts.length} post{filteredPosts.length !== 1 ? "s" : ""}
39+
The latest and greatest news regarding updates, changes and more. Prism
40+
Launcher now supports viewing news directly in the Launcher by clicking
41+
the news icon at the bottom of the window.
4042
</p>
43+
<TagFilter activeTag={tag} />
4144
</ProseCard>
4245

4346
{

0 commit comments

Comments
 (0)