Skip to content

Commit 30041bb

Browse files
committed
refactor: extract post meta data to PostMeta component
1 parent 71a183f commit 30041bb

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/components/PostMeta.astro

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import { formatDate } from '@/lib/utils';
3+
import type { PostFrontmatter } from '@/schemas/post';
4+
5+
type Props = Pick<PostFrontmatter, 'title' | 'pubDate' | 'description'>;
6+
7+
const { title, pubDate, description } = Astro.props;
8+
---
9+
10+
<header>
11+
<h1>{title}</h1>
12+
<time
13+
class="text-xs sm:text-sm text-muted-foreground/70"
14+
datetime={pubDate.toISOString()}>{formatDate(pubDate)}</time
15+
>
16+
{
17+
description && (
18+
<p class=" text-neutral-500 border-l-2 border-primary/20 pl-4 py-1">
19+
{description}
20+
</p>
21+
)
22+
}
23+
</header>

src/layouts/PostLayout.astro

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
import { formatDate } from '@/lib/utils';
33
import BaseLayout from './BaseLayout.astro';
4+
import PostMeta from '@/components/PostMeta.astro';
45
56
const { post } = Astro.props;
67
const { title, pubDate, description, update } = post.data;
7-
88
---
99

1010
<BaseLayout>
@@ -21,18 +21,7 @@ const { title, pubDate, description, update } = post.data;
2121
/* 列表 */
2222
prose-li:my-1"
2323
>
24-
<h1>{title}</h1>
25-
<time
26-
class="text-xs sm:text-sm text-muted-foreground/70"
27-
datetime={pubDate.toISOString()}>{formatDate(pubDate)}</time
28-
>
29-
{
30-
description && (
31-
<p class=" text-neutral-500 border-l-2 border-primary/20 pl-4 py-1">
32-
{description}
33-
</p>
34-
)
35-
}
24+
<PostMeta title={title} pubDate={pubDate} description={description} />
3625
<slot />
3726
</article>
3827
<div class="mt-20 border-t border-dashed pt-6 space-y-6">

0 commit comments

Comments
 (0)