import { ImageResponse } from '@vercel/og'; import { NextRequest } from 'next/server'; export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url); // Get parameters const title = searchParams.get('title') || 'Blog Post'; const description = searchParams.get('description') || ''; const tags = searchParams.get('tags')?.split(',').slice(0, 3) || []; return new ImageResponse( (
{/* Header with gradient */}
個人部落格
{/* Main content */}
{/* Title */}
{title}
{/* Description */} {description && (
{description}
)} {/* Tags */} {tags.length > 0 && (
{tags.map((tag, i) => (
#{tag.trim()}
))}
)}
{/* Footer with accent line */}
gbanyan.net
), { width: 1200, height: 630, } ); } catch (e: any) { console.error('Error generating OG image:', e); return new Response(`Failed to generate image: ${e.message}`, { status: 500, }); } }