Skip to content

Commit cc3bec3

Browse files
committed
Fix: 한글 지원 이후 포스트 못불러오던 문제 해결
1 parent bebceae commit cc3bec3

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

app/(blog)/posts/[...slug]/page.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,35 @@ export async function generateStaticParams() {
1414
return [{ slug: ["no-post"] }];
1515
}
1616

17-
return posts.map((post) => ({
18-
slug: post.urlPath.split("/").map(segment => encodeURIComponent(segment)),
19-
}));
17+
// 로깅 추가
18+
console.log("Generating static params for posts:");
19+
20+
return posts.map((post) => {
21+
// 인코딩하지 않고 원래 경로 세그먼트 사용
22+
const slugSegments = post.urlPath.split("/");
23+
console.log(`Post path: ${post.urlPath} -> Segments: ${slugSegments.join("/")}`);
24+
25+
return {
26+
slug: slugSegments,
27+
};
28+
});
2029
}
2130

2231
export default async function PostPage({ params }: PostPageProps) {
2332
const { slug } = await params;
24-
const decodedSlug = slug.map((s) => decodeURIComponent(s)).filter(Boolean);
33+
console.log("Raw URL slug segments:", slug);
34+
35+
// 모든 세그먼트를 명시적으로 디코딩
36+
const decodedSlug = slug.map((s) => {
37+
try {
38+
return decodeURIComponent(s);
39+
} catch (e) {
40+
console.error(`Failed to decode segment "${s}":`, e);
41+
return s; // 디코딩 실패 시 원본 유지
42+
}
43+
}).filter(Boolean);
44+
45+
console.log("Decoded slug:", decodedSlug);
2546
const post = await getPost(decodedSlug);
2647

2748
if (!post) {

components/post-card.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ const PostCard = ({
5353
(summary || plainContent || content).substring(0, 150) + "...";
5454

5555
return (
56-
<Link href={`/posts/${encodeURIComponent(urlPath)}`} className="block h-full">
56+
<Link
57+
href={`/posts/${urlPath}`}
58+
className="block h-full">
5759
<motion.div
5860
className="h-full group overflow-hidden rounded-lg border border-border bg-card shadow-sm hover:shadow-md"
5961
whileHover={{

lib/posts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export async function getPost(slug: string[]): Promise<Post | null> {
137137
return null;
138138
}
139139

140-
// URL로 전달된 인코딩된 슬러그를 디코딩
140+
// URL 슬러그 처리 - 인코딩/디코딩 없이 사용
141141
const urlPath = slug.join("/").replace(/\/+/g, "/").replace(/\.md$/, "");
142+
console.log("Getting post with urlPath:", urlPath);
142143

143144
try {
144145
// 메타데이터 타입 안전성 강화

0 commit comments

Comments
 (0)