mirror of
https://github.com/Dokploy/website.git
synced 2026-06-15 20:25:25 +02:00
- Updated various files to ensure consistent code formatting, including adjusting indentation and spacing. - Refactored components and utility functions for better readability and maintainability. - Removed unnecessary newlines and ensured consistent use of single quotes for strings across the codebase.
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { getPost } from '@/lib/ghost'
|
|
import { generateOGImage } from '@/lib/og-image'
|
|
import type { NextRequest } from 'next/server'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
const slug = searchParams.get('slug')
|
|
|
|
console.log('Generating OG image for slug:', slug)
|
|
|
|
if (!slug) {
|
|
console.error('Missing slug parameter')
|
|
return new Response('Missing slug parameter', { status: 400 })
|
|
}
|
|
|
|
const post = await getPost(slug)
|
|
|
|
if (!post) {
|
|
console.error('Post not found for slug:', slug)
|
|
return new Response('Post not found', { status: 404 })
|
|
}
|
|
|
|
const formattedDate = new Date(post.published_at).toLocaleDateString(
|
|
'en-US',
|
|
{
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
},
|
|
)
|
|
|
|
const ogImage = await generateOGImage({
|
|
title: post.title,
|
|
author: post.primary_author
|
|
? {
|
|
name: post.primary_author.name,
|
|
image: post.primary_author.profile_image || undefined,
|
|
}
|
|
: undefined,
|
|
date: formattedDate,
|
|
readingTime: post.reading_time,
|
|
})
|
|
|
|
return new Response(ogImage, {
|
|
headers: {
|
|
'Content-Type': 'image/png',
|
|
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
},
|
|
})
|
|
} catch (error) {
|
|
console.error('Error generating OG image:', error)
|
|
return new Response(`Error generating image: ${error}`, { status: 500 })
|
|
}
|
|
}
|