diff --git a/app/[id]/opengraph-image.tsx b/app/[id]/opengraph-image.tsx index a393c11..e24953f 100644 --- a/app/[id]/opengraph-image.tsx +++ b/app/[id]/opengraph-image.tsx @@ -4,6 +4,8 @@ import { getPoem, splitPoemText } from "libs/utils"; import { SiteInfo } from "data/site"; +import { Poem } from "types/poem"; + export const runtime = "edge"; export const alt = SiteInfo.description; @@ -22,17 +24,19 @@ export default async function Image({ params }: { params: { id: string } }) { }); } - const kiwiMaru = fetch( - new URL( - "https://fonts.bunny.net/kiwi-maru/files/kiwi-maru-japanese-400-normal.woff" - ) - ).then((res) => res.arrayBuffer()); + const kiwiMaru = await fetchFont(poem); + if (!kiwiMaru) { + return new Response("Failed to fetch font", { + status: 500 + }); + } const lines = splitPoemText(poem.text); return new ImageResponse( (
{ + // Kiwi Maru + const API = `https://fonts.googleapis.com/css2?family=Kiwi+Maru&text=${encodeURIComponent( + clothesName + idolName + text + )}`; + + const css = await ( + await fetch(API, { + headers: { + // Make sure it returns TTF. + "User-Agent": + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" + } + }) + ).text(); + + const resource = css.match( + /src: url\((.+)\) format\('(opentype|truetype)'\)/ + ); + + if (!resource) return null; + + const res = await fetch(resource[1]); + + return res.arrayBuffer(); +}