import { ImageResponse } from "next/og"; import { getBook } from "@community/lib/ebook/book.server"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; export const alt = "Ebook cover"; export const size = { width: 1200, height: 630 }; export const contentType = "image/png"; async function loadFont() { const urls = [ "https://cdn.jsdelivr.net/fontsource/fonts/noto-sans-sc@5.0.0/chinese-simplified-700-normal.woff", "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYAZ9hiJ-Ek-_EeA.woff2", ]; for (const url of urls) { try { const res = await fetch(url, { cache: "force-cache" }); if (res.ok) return { data: await res.arrayBuffer(), name: url.includes("noto") ? "Noto Sans SC" : "Inter" }; } catch { /* try next */ } } const inter = await fetch( "https://fonts.gstatic.com/s/inter/v13/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYAZ9hiJ-Ek-_EeA.woff2" ); return { data: await inter.arrayBuffer(), name: "Inter" }; } export default async function OgImage() { const book = getBook(); const font = await loadFont(); return new ImageResponse( (
{book.viralTags.slice(0, 4).map((tag) => ( #{tag} ))}
FREE EBOOK
{book.title}
{book.subtitle}
{book.tagline}
{book.chapters.length} 章 · 约 {book.readingMinutes} 分钟 · by {book.author}
点击免费阅读 →
), { ...size, fonts: [{ name: font.name, data: font.data, style: "normal" as const, weight: 700 }], } ); }