All checks were successful
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 20s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m30s
Build & Deploy KLZ Cables / 🏗️ Build & Push (push) Successful in 3m14s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Successful in 42s
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Successful in 5m0s
Build & Deploy KLZ Cables / 🔔 Notifications (push) Successful in 2s
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { ImageResponse } from 'next/og';
|
|
import { getPostBySlug } from '@/lib/blog';
|
|
import { OGImageTemplate } from '@/components/OGImageTemplate';
|
|
import { getOgFonts, OG_IMAGE_SIZE } from '@/lib/og-helper';
|
|
import { SITE_URL } from '@/lib/schema';
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
export default async function Image({
|
|
params: { locale, slug },
|
|
}: {
|
|
params: { locale: string; slug: string };
|
|
}) {
|
|
const post = await getPostBySlug(slug, locale);
|
|
|
|
if (!post) {
|
|
return new Response('Post not found', { status: 404 });
|
|
}
|
|
|
|
const fonts = await getOgFonts();
|
|
|
|
// We don't have request.url here, but we can assume the domain from SITE_URL or config
|
|
// For local images during dev, relative paths in <img> might not work in Satori
|
|
// but if we are in nodejs runtime, we could potentially read from disk.
|
|
// For now, let's just make sure it's absolute.
|
|
const featuredImage = post.frontmatter.featuredImage
|
|
? post.frontmatter.featuredImage.startsWith('http')
|
|
? post.frontmatter.featuredImage
|
|
: `${SITE_URL}${post.frontmatter.featuredImage}`
|
|
: undefined;
|
|
|
|
return new ImageResponse(
|
|
<OGImageTemplate
|
|
title={post.frontmatter.title}
|
|
description={post.frontmatter.excerpt}
|
|
label={post.frontmatter.category || 'Blog'}
|
|
image={featuredImage}
|
|
/>,
|
|
{
|
|
...OG_IMAGE_SIZE,
|
|
fonts,
|
|
},
|
|
);
|
|
}
|