Skip to content

Commit 610919b

Browse files
committed
Change tag display for PostPreview component and post page
1 parent 8d5f9ef commit 610919b

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

src/components/PostPreview.astro

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { dateString } from '@utils'
33
import { Icon } from 'astro-icon/components'
44
import type { CollectionEntry } from 'astro:content'
55
import { render } from 'astro:content'
6+
import Tags from './Tags.astro'
67
78
interface Props {
89
post: CollectionEntry<'posts'>
@@ -39,15 +40,8 @@ const description = remarkPluginFrontmatter.description || post.data.description
3940
{description && <p class="my-4 text-base/7 text-foreground">{description}</p>}
4041
{
4142
post.data.tags && (
42-
<div class="text-accent mb-6">
43-
{post.data.tags.map((tag) => (
44-
<a
45-
class="underline mr-4 inline-block"
46-
href={`/tags/${encodeURIComponent(tag)}`}
47-
>
48-
#{tag}
49-
</a>
50-
))}
43+
<div class="mb-6">
44+
<Tags tags={post.data.tags} />
5145
</div>
5246
)
5347
}

src/components/Tags.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
interface Props {
3+
tags: string[]
4+
}
5+
6+
const { tags } = Astro.props
7+
---
8+
9+
<div class="flex flex-wrap gap-3 text-sm">
10+
<slot />
11+
{
12+
tags.map((tag) => (
13+
<a
14+
href={`/tags/${encodeURIComponent(tag)}`}
15+
class="py-1 px-3 bg-accent/2 hover:bg-accent/10 border-1 border-accent/10 text-accent/90 rounded-2xl"
16+
>
17+
{tag}
18+
</a>
19+
))
20+
}
21+
</div>

src/content/posts/showing-off-blog-features/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Showing Off Blog Features'
33
published: 2025-07-20
44
draft: false
5-
tags: ['astro']
5+
tags: ['astro', 'demo', 'markdown']
66
toc: true
77
coverImage:
88
src: './cover.jpg'

src/pages/posts/[...page].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getStaticPaths = (async ({ paginate }) => {
1616
const { page } = Astro.props
1717
---
1818

19-
<Layout>
19+
<Layout title="Archive" description="All posts in the archive">
2020
<BlockHeader>Archive</BlockHeader>
2121
<PostPreviewsWithYear posts={page.data} />
2222
<Pagination

src/pages/posts/[slug].astro

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import TableOfContents from '@components/TableOfContents.astro'
1010
import { Image } from 'astro:assets'
1111
import GiscusLoader from '@components/GiscusLoader.astro'
1212
import siteConfig from '../../site.config'
13+
import Tags from '@components/Tags.astro'
1314
1415
export const getStaticPaths = (async () => {
1516
const posts = await getSortedPosts()
@@ -59,7 +60,7 @@ if (addendum.length > 0) {
5960
<h1 class="mb-3 text-[1.75rem] text-[var(--theme-h1)] font-semibold">
6061
# {postData.title}
6162
</h1>
62-
<div class="text-foreground/80 mb-2.5">
63+
<div class="text-foreground/80 mb-1">
6364
<time>{dateString(postData.published)}</time>
6465
{
6566
postData.author && (
@@ -68,21 +69,14 @@ if (addendum.length > 0) {
6869
</span>
6970
)
7071
}
71-
</div>
7272
{
7373
postData.tags && (
74-
<div class="text-accent mb-5 lg:mb-0">
75-
{postData.tags.map((tag) => (
76-
<a
77-
class="underline mr-4 inline-block"
78-
href={`/tags/${encodeURIComponent(tag)}`}
79-
>
80-
#{tag}
81-
</a>
82-
))}
74+
<div class="mt-4">
75+
<Tags tags={postData.tags} />
8376
</div>
8477
)
8578
}
79+
</div>
8680
</div>
8781
<!-- <hr class="border-accent/10 border-2 rounded-xl hidden lg:block" /> -->
8882
<div class="flex flex-col xl:gap-4 2xl:gap-18 xl:flex-row xl:items-start">

src/pages/tags/[tag]/[...page].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ export const getStaticPaths = (async ({ paginate }) => {
2323
2424
const { page } = Astro.props
2525
const { tag } = Astro.params
26+
const title = `Tag: ${tag}`
2627
---
2728

28-
<Layout>
29-
<BlockHeader>#{tag}</BlockHeader>
29+
<Layout title={title} description={`All posts tagged with ${tag}`}>
30+
<BlockHeader>{title}</BlockHeader>
3031
<PostPreviewsWithYear posts={page.data} />
3132
<Pagination
3233
prevLink={page.url.prev ? encodeURI(page.url.prev) : undefined}

0 commit comments

Comments
 (0)