Replace reverse-proxy/iframe approach with @ebook/@community/@navmini imports under /nav /book /community so localhost:3000 serves all three products directly. Co-authored-by: Cursor <cursoragent@cursor.com>
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
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(
|
|
(
|
|
<div
|
|
style={{
|
|
width: "100%",
|
|
height: "100%",
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
justifyContent: "space-between",
|
|
padding: "56px 64px",
|
|
background: "linear-gradient(135deg, #1a0b2e 0%, #5b21b6 42%, #db2777 78%, #ea580c 100%)",
|
|
color: "#fff",
|
|
fontFamily: font ? font.name : "sans-serif",
|
|
}}
|
|
>
|
|
<div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
|
|
{book.viralTags.slice(0, 4).map((tag) => (
|
|
<span
|
|
key={tag}
|
|
style={{
|
|
fontSize: 22,
|
|
padding: "8px 18px",
|
|
borderRadius: 999,
|
|
background: "rgba(255,255,255,0.14)",
|
|
border: "1px solid rgba(255,255,255,0.22)",
|
|
}}
|
|
>
|
|
#{tag}
|
|
</span>
|
|
))}
|
|
</div>
|
|
|
|
<div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
|
|
<div style={{ fontSize: 28, opacity: 0.75, letterSpacing: 4 }}>FREE EBOOK</div>
|
|
<div style={{ fontSize: 72, fontWeight: 700, lineHeight: 1.1, maxWidth: 980 }}>
|
|
{book.title}
|
|
</div>
|
|
<div style={{ fontSize: 34, opacity: 0.88, maxWidth: 900 }}>{book.subtitle}</div>
|
|
<div style={{ fontSize: 26, opacity: 0.72, maxWidth: 860 }}>{book.tagline}</div>
|
|
</div>
|
|
|
|
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
|
|
<div style={{ fontSize: 24, opacity: 0.7 }}>
|
|
{book.chapters.length} 章 · 约 {book.readingMinutes} 分钟 · by {book.author}
|
|
</div>
|
|
<div
|
|
style={{
|
|
fontSize: 22,
|
|
padding: "14px 28px",
|
|
borderRadius: 999,
|
|
background: "#fff",
|
|
color: "#4c1d95",
|
|
fontWeight: 700,
|
|
}}
|
|
>
|
|
点击免费阅读 →
|
|
</div>
|
|
</div>
|
|
</div>
|
|
),
|
|
{
|
|
...size,
|
|
fonts: [{ name: font.name, data: font.data, style: "normal" as const, weight: 700 }],
|
|
}
|
|
);
|
|
}
|