1- import { getPublishedPosts , getPostBySlug } from "@/lib/services/blog-service" ;
1+ import { getPublishedPostBySlug , getPublishedPosts } from "@/lib/services/blog-service" ;
22import { notFound } from "next/navigation" ;
33import Link from "next/link" ;
44import Image from "next/image" ;
55import { ArrowLeft , Clock , Share2 } from "lucide-react" ;
66import Footer from "@/components/Footer" ;
77import { EnhancedMarkdown } from "@/components/EnhancedMarkdown" ;
88import { BlogPost } from "@prisma/client" ;
9+ import { Metadata } from "next" ;
910
1011// Generates static params for all blog posts
1112export async function generateStaticParams ( ) {
@@ -15,9 +16,56 @@ export async function generateStaticParams() {
1516 } ) ) ;
1617}
1718
19+ export async function generateMetadata ( { params } : { params : Promise < { slug : string } > } ) : Promise < Metadata > {
20+ const { slug } = await params ;
21+ const post = await getPublishedPostBySlug ( slug ) ;
22+
23+ if ( ! post ) {
24+ return {
25+ title : "Post Not Found" ,
26+ robots : {
27+ index : false ,
28+ follow : false ,
29+ } ,
30+ } ;
31+ }
32+
33+ const canonicalPath = `/blog/${ post . slug } ` ;
34+ const publishedTime = ( post . publishedAt ?? post . createdAt ) . toISOString ( ) ;
35+
36+ return {
37+ title : post . title ,
38+ description : post . excerpt ,
39+ alternates : {
40+ canonical : canonicalPath ,
41+ } ,
42+ openGraph : {
43+ title : post . title ,
44+ description : post . excerpt ,
45+ type : "article" ,
46+ url : canonicalPath ,
47+ images : [
48+ {
49+ url : post . image ,
50+ alt : post . title ,
51+ } ,
52+ ] ,
53+ publishedTime,
54+ modifiedTime : post . updatedAt . toISOString ( ) ,
55+ authors : [ post . author ] ,
56+ } ,
57+ twitter : {
58+ card : "summary_large_image" ,
59+ title : post . title ,
60+ description : post . excerpt ,
61+ images : [ post . image ] ,
62+ } ,
63+ } ;
64+ }
65+
1866export default async function BlogPostPage ( { params } : { params : Promise < { slug : string } > } ) {
1967 const { slug } = await params ;
20- const post = await getPostBySlug ( slug ) ;
68+ const post = await getPublishedPostBySlug ( slug ) ;
2169
2270 if ( ! post ) {
2371 notFound ( ) ;
0 commit comments