11import type { Metadata } from "next" ;
22import Image from "next/image" ;
33import { notFound } from "next/navigation" ;
4+ import { cache } from "react" ;
45import { and , desc , eq } from "drizzle-orm" ;
56import PostContent , {
67 type TiptapJson ,
78} from "@/components/blog/PostContent" ;
89import Badge from "@/components/ui/Badge" ;
910import { blogPosts , db } from "@/db" ;
11+ import { getOptimisedUrl } from "@/lib/cloudinary" ;
12+
13+ export const revalidate = 3600 ;
1014
1115type UpdatePageProps = {
1216 params : {
@@ -30,7 +34,7 @@ function isTiptapJson(value: unknown): value is TiptapJson {
3034 return typeof value === "object" && value !== null && ! Array . isArray ( value ) ;
3135}
3236
33- async function getPublishedPostBySlug ( slug : string ) {
37+ const getPublishedPostBySlug = cache ( async ( slug : string ) => {
3438 try {
3539 const [ post ] = await db
3640 . select ( )
@@ -39,11 +43,10 @@ async function getPublishedPostBySlug(slug: string) {
3943 . limit ( 1 ) ;
4044
4145 return post ?? null ;
42- } catch ( error ) {
43- console . error ( "Failed to fetch update" , error ) ;
46+ } catch {
4447 return null ;
4548 }
46- }
49+ } ) ;
4750
4851export async function generateStaticParams ( ) {
4952 if ( process . env . CI === "true" ) {
@@ -70,13 +73,34 @@ export async function generateMetadata({
7073
7174 if ( ! post ) {
7275 return {
73- title : "Update \u2014 CodedDevs Updates" ,
76+ title : "Update — CodedDevs Updates" ,
7477 } ;
7578 }
7679
80+ const title = `${ post . title } — CodedDevs Updates` ;
81+ const description = post . excerpt ;
82+ const url = `https://codeddevs.com/blog/${ post . slug } ` ;
83+ const images = post . cover_url
84+ ? [ { url : getOptimisedUrl ( post . cover_url ) , alt : post . title } ]
85+ : undefined ;
86+
7787 return {
78- title : `${ post . title } \u2014 CodedDevs Updates` ,
79- description : post . excerpt ,
88+ title,
89+ description,
90+ openGraph : {
91+ title,
92+ description,
93+ url,
94+ siteName : "CodedDevs Technology LTD" ,
95+ type : "article" ,
96+ images,
97+ } ,
98+ twitter : {
99+ card : "summary_large_image" ,
100+ title,
101+ description,
102+ images : images ?. map ( ( image ) => image . url ) ,
103+ } ,
80104 } ;
81105}
82106
@@ -113,7 +137,7 @@ export default async function UpdatePage({ params }: UpdatePageProps) {
113137 < div className = "mx-auto max-w-5xl px-6" >
114138 < div className = "relative aspect-[16/9] overflow-hidden rounded-lg bg-[#F4F5F8]" >
115139 < Image
116- src = { post . cover_url }
140+ src = { getOptimisedUrl ( post . cover_url ) }
117141 alt = { post . title }
118142 fill
119143 sizes = "(min-width: 1024px) 1024px, 100vw"
0 commit comments