1+ import type { Metadata } from 'next' ;
12import { notFound } from 'next/navigation' ;
23
34import { getAllPostSlugs , getPost } from '@/shared/lib' ;
@@ -13,6 +14,57 @@ export async function generateStaticParams() {
1314 return slugs . map ( ( slug ) => ( { id : slug } ) ) ;
1415}
1516
17+ export async function generateMetadata ( {
18+ params,
19+ } : PostDetailPageProps ) : Promise < Metadata > {
20+ const { id } = await params ;
21+ const post = getPost ( id ) ;
22+
23+ if ( ! post ) {
24+ return {
25+ title : '포스트를 찾을 수 없습니다' ,
26+ } ;
27+ }
28+
29+ const baseUrl = 'https://dobbymin.github.io' ;
30+ const postUrl = `${ baseUrl } /post/${ id } ` ;
31+ const thumbnailUrl = post . thumbnail
32+ ? `${ baseUrl } ${ post . thumbnail } `
33+ : `${ baseUrl } /logo.png` ;
34+
35+ return {
36+ title : post . title ,
37+ description : post . description ,
38+ keywords : [ post . category , post . title , '개발 블로그' ] ,
39+ authors : [ { name : '김도비' , url : 'https://github.com/Dobbymin' } ] ,
40+ creator : '김도비' ,
41+ openGraph : {
42+ type : 'article' ,
43+ locale : 'ko_KR' ,
44+ url : postUrl ,
45+ title : post . title ,
46+ description : post . description ,
47+ siteName : 'Dobby is Free' ,
48+ publishedTime : post . date ,
49+ authors : [ '김도비' ] ,
50+ images : [
51+ {
52+ url : thumbnailUrl ,
53+ width : 1200 ,
54+ height : 630 ,
55+ alt : post . title ,
56+ } ,
57+ ] ,
58+ } ,
59+ twitter : {
60+ card : 'summary_large_image' ,
61+ title : post . title ,
62+ description : post . description ,
63+ images : [ thumbnailUrl ] ,
64+ } ,
65+ } ;
66+ }
67+
1668export default async function PostDetailPage ( { params } : PostDetailPageProps ) {
1769 const { id } = await params ;
1870 const post = getPost ( id ) ;
0 commit comments