Skip to content

Commit bb28c3a

Browse files
committed
feat: display tags on blog page
1 parent c39f863 commit bb28c3a

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/components/Navbar.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ArrowUpRight from "./ArrowUpRight.astro";
1111
<a class="py-2 hover:underline" href="/"> Home </a>
1212
</li>
1313
<li>
14-
<a class="py-2 hover:underline" href="/blog"> Posts </a>
14+
<a class="py-2 hover:underline" href="/blog"> Blog </a>
1515
</li>
1616
<li>
1717
<a

src/components/Tags.astro

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2+
interface Props {
3+
tags: string[];
4+
}
5+
26
const { tags } = Astro.props;
37
---
48

59
<div>
6-
<h1 class="my-8 mb-2 tracking-wider text-gray-900 dark:text-gray-100">
7-
Tags
8-
</h1>
9-
<ul class="flex flex-wrap">
10+
<ul class="mb-6 flex flex-wrap">
1011
{
1112
tags.map((tag: unknown) => (
12-
<li class="mr-3 text-sm font-medium text-gray-400 hover:underline dark:text-gray-600">
13-
<a href={`/tags/${tag}`}>{`#${tag}`}</a>
13+
<li class="mr-3 text-sm font-medium text-gray-600 hover:underline dark:text-gray-400">
14+
<a href={`/tags/${tag}`}>{tag}</a>
1415
</li>
1516
))
1617
}

src/pages/blog/index.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import { getCollection } from "astro:content";
33
import BlogPostCard from "../../components/BlogPostCard.astro";
44
import Navbar from "../../components/Navbar.astro";
55
import BaseLayout from "../../layouts/BaseLayout.astro";
6+
import Tags from "../../components/Tags.astro";
67
78
const posts = await getCollection("blog", ({ data }) => data.draft !== true);
89
const orderedPosts = posts.sort((a, b) => {
910
const aDate = new Date(a.data.pubDate);
1011
const bDate = new Date(b.data.pubDate);
1112
return bDate.valueOf() - aDate.valueOf();
1213
});
14+
const tags = [...new Set(posts.map((post) => post.data.tags).flat())];
1315
---
1416

1517
<BaseLayout title="Milán Herke - Blog">
1618
<Navbar />
19+
<h1 class="mb-1 mt-4 lowercase text-gray-900 dark:text-gray-100">Posts</h1>
20+
<Tags tags={tags} />
1721
{orderedPosts.map((post) => <BlogPostCard post={post} />)}
1822
</BaseLayout>

src/pages/tags/[tag].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const allPosts = await getCollection(
2525

2626
<BaseLayout title="Milán Herke - Blog">
2727
<Navbar />
28-
<h1 class="my-8 mb-2 tracking-wider text-gray-900 dark:text-gray-100">
29-
Posts with {tag} tag
28+
<h1 class="mb-6 mt-4 lowercase text-gray-900 dark:text-gray-100">
29+
Posts tagged with {tag}
3030
</h1>
3131
{allPosts.map((post) => <BlogPostCard post={post} />)}
3232
</BaseLayout>

0 commit comments

Comments
 (0)