-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogPostPage.tsx
More file actions
182 lines (166 loc) · 5.26 KB
/
Copy pathBlogPostPage.tsx
File metadata and controls
182 lines (166 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import {
getFeedData,
getAllFeedSlugs,
getSeriesPosts,
} from '@/features/blog/services/post-repository';
import {
getMdxSource,
parseHeadingsFromMdx,
} from '@/features/blog/services/markdown-parser';
import { Container } from '@/shared/layout';
import {
ReadingProgress,
TableOfContents,
GiscusComments,
SeriesNavigation,
ViewCounter,
} from '@/features/blog/ui/components';
import PostViewTracker from '@/shared/analytics/components/PostViewTracker';
import DwellTimeTracker from '@/shared/analytics/components/DwellTimeTracker';
import ScrollDepthTracker from '@/shared/analytics/components/ScrollDepthTracker';
import JsonLd from '@/shared/seo/JsonLd';
import { getMDXComponents } from '@/features/blog/ui/mdx/components';
import { SITE_URL } from '@/core/config/site';
export async function generateStaticParams() {
return getAllFeedSlugs();
}
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>;
}): Promise<Metadata> {
const { slug } = await params;
const post = await getFeedData(slug);
if (!post) {
return { title: '글을 찾을 수 없습니다' };
}
return {
title: post.title,
description: post.description,
openGraph: {
title: post.title,
description: post.description,
type: 'article',
publishedTime: post.date,
authors: ['Eunu'],
tags: post.tags,
images: [
{
url: `/api/og?title=${encodeURIComponent(post.title)}&date=${post.date}&tags=${post.tags?.join(',') || ''}`,
width: 1200,
height: 630,
alt: post.title,
},
],
},
};
}
export default async function BlogPostPage({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
const post = await getFeedData(slug);
if (!post) {
notFound();
}
const mdxSource = getMdxSource(slug);
const tocItems = mdxSource ? parseHeadingsFromMdx(mdxSource) : [];
// Get series posts if this post belongs to a series
const seriesPosts = post.series ? getSeriesPosts(post.series.id) : [];
const { Content } = post;
const formattedDate = new Date(post.date).toLocaleDateString('ko-KR', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
const readingTimeLabel = post.readingTime ? `약 ${post.readingTime}분` : null;
const mdxComponents = getMDXComponents({});
return (
<>
<ReadingProgress />
<PostViewTracker
slug={post.slug}
category={post.category}
tags={post.tags}
/>
<DwellTimeTracker slug={post.slug} />
<ScrollDepthTracker slug={post.slug} />
<article className="py-10">
<Container size="md">
{/* Header */}
<header className="mb-10">
<span className="inline-block px-3 py-1 text-sm font-medium text-[var(--color-toss-blue)] bg-[var(--color-toss-blue)]/10 rounded-full mb-4">
{post.category}
</span>
<h1 className="text-3xl md:text-4xl font-bold text-[var(--color-grey-900)] leading-tight">
{post.title}
</h1>
<div className="mt-6 flex flex-wrap items-center gap-4 text-sm text-[var(--color-grey-500)]">
<time>{formattedDate}</time>
{readingTimeLabel && (
<>
<span className="w-1 h-1 bg-[var(--color-grey-300)] rounded-full" />
<span>{readingTimeLabel}</span>
</>
)}
<span className="w-1 h-1 bg-[var(--color-grey-300)] rounded-full" />
<ViewCounter slug={post.slug} />
</div>
{post.tags && (
<div className="mt-4 flex flex-wrap items-center gap-2">
{post.tags.map((tag) => (
<span
key={tag}
className="text-xs text-[var(--color-grey-500)] bg-[var(--color-grey-100)] px-2 py-1 rounded"
>
#{tag}
</span>
))}
</div>
)}
</header>
{/* Series Navigation */}
{post.series && seriesPosts.length > 0 && (
<SeriesNavigation
currentSlug={post.slug}
seriesTitle={post.series.title}
seriesPosts={seriesPosts}
currentOrder={post.series.order}
/>
)}
{/* Content */}
<div className="prose">
<Content components={mdxComponents} />
</div>
</Container>
</article>
{/* Comments */}
<section className="py-12">
<Container size="md">
<GiscusComments slug={slug} />
</Container>
</section>
<JsonLd
data={{
'@context': 'https://schema.org',
'@type': 'BlogPosting',
headline: post.title,
description: post.description,
author: {
'@type': 'Person',
name: 'Eunu',
},
datePublished: post.date,
image: [
`${SITE_URL}/api/og?title=${encodeURIComponent(post.title)}&date=${post.date}&tags=${post.tags?.join(',') || ''}`,
],
}}
/>
<TableOfContents items={tocItems} />
</>
);
}