Skip to content

Commit eef87ce

Browse files
committed
Create PostInfo component and tweak post headings
1 parent 13d552a commit eef87ce

5 files changed

Lines changed: 44 additions & 34 deletions

File tree

src/components/PostInfo.astro

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
import { dateString } from '@utils'
3+
import { renderComponentToString } from 'astro/runtime/server/render/component.js'
4+
import { render, type CollectionEntry } from 'astro:content'
5+
6+
interface Props {
7+
post: CollectionEntry<'posts'>
8+
class?: string
9+
}
10+
11+
const { post, class: className } = Astro.props
12+
const { remarkPluginFrontmatter } = await render(post)
13+
const { minutesRead } = remarkPluginFrontmatter
14+
---
15+
16+
<div class:list={[className, 'text-foreground/80']}>
17+
<time>{dateString(post.data.published)}</time>
18+
{
19+
post.data.author && (
20+
<span class="before:content-['::'] before:inline-block before:mx-0.5">
21+
{post.data.author}
22+
</span>
23+
)
24+
}
25+
{
26+
minutesRead && (
27+
<span class="before:content-['::'] before:inline-block before:mx-0.5">
28+
{minutesRead}
29+
</span>
30+
)
31+
}
32+
</div>

src/components/PostPreview.astro

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ 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'
6+
import Tags from '@components/Tags.astro'
7+
import PostInfo from '@components/PostInfo.astro'
78
89
interface Props {
910
post: CollectionEntry<'posts'>
@@ -12,31 +13,14 @@ interface Props {
1213
const { post } = Astro.props
1314
1415
const { remarkPluginFrontmatter } = await render(post)
15-
const { minutesRead } = remarkPluginFrontmatter
1616
const description = remarkPluginFrontmatter.description || post.data.description
1717
---
1818

1919
<article class="w-full py-5 my-1 md:my-4 border-accent/10">
2020
<h1 class="mb-3 text-2xl text-[var(--theme-h1)] font-semibold">
2121
<a href={`/posts/${post.id}`}># {post.data.title}</a>
2222
</h1>
23-
<div class="text-foreground/80 my-3">
24-
<time>{dateString(post.data.published)}</time>
25-
{
26-
post.data.author && (
27-
<span class="before:content-['::'] before:inline-block before:mx-0.5">
28-
{post.data.author}
29-
</span>
30-
)
31-
}
32-
{
33-
minutesRead && (
34-
<span class="before:content-['::'] before:inline-block before:mx-0.5">
35-
{minutesRead}
36-
</span>
37-
)
38-
}
39-
</div>
23+
<PostInfo post={post} class="my-3" />
4024
{description && <p class="my-4 text-base/7 text-foreground">{description}</p>}
4125
{
4226
post.data.tags && (

src/components/Tags.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { tags } = Astro.props
1212
tags.map((tag) => (
1313
<a
1414
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 transition-colors"
15+
class="py-1 px-3 bg-accent/1 hover:bg-accent/8 border-1 border-accent/10 text-accent/90 rounded-2xl transition-colors"
1616
>
1717
{tag}
1818
</a>

src/pages/posts/[slug].astro

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Image } from 'astro:assets'
1111
import GiscusLoader from '@components/GiscusLoader.astro'
1212
import siteConfig from '../../site.config'
1313
import Tags from '@components/Tags.astro'
14+
import PostInfo from '@components/PostInfo.astro'
1415
1516
export const getStaticPaths = (async () => {
1617
const posts = await getSortedPosts()
@@ -60,22 +61,15 @@ if (addendum.length > 0) {
6061
<h1 class="mb-4 text-[1.75rem] text-[var(--theme-h1)] font-semibold">
6162
# {postData.title}
6263
</h1>
63-
<div class="text-foreground/80 mb-1">
64-
<time>{dateString(postData.published)}</time>
64+
<div class="my-2 border-l-2 border-accent/80 pl-4 py-2">
65+
<PostInfo post={post} class="mb-1" />
6566
{
66-
postData.author && (
67-
<span class="before:content-['::'] before:inline-block before:mx-0.5">
68-
{postData.author}
69-
</span>
67+
postData.tags && (
68+
<div class="mt-4">
69+
<Tags tags={postData.tags} />
70+
</div>
7071
)
7172
}
72-
{
73-
postData.tags && (
74-
<div class="mt-4">
75-
<Tags tags={postData.tags} />
76-
</div>
77-
)
78-
}
7973
</div>
8074
</div>
8175
<!-- <hr class="border-accent/10 border-2 rounded-xl hidden lg:block" /> -->

src/styles/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ button {
7777
}
7878

7979
a.button {
80-
@apply inline-flex text-accent border-3 border-accent/30 border-double py-1.5 px-3 whitespace-nowrap hover:bg-accent/10 rounded-xl transition-colors;
80+
@apply inline-flex text-accent border-3 border-accent/30 border-double py-1.5 px-3 whitespace-nowrap hover:bg-accent/8 rounded-xl transition-colors;
8181
}
8282

8383
header button,

0 commit comments

Comments
 (0)