Skip to content

Commit a1fc4bc

Browse files
authored
fix: OG image error from custom fonts not being supported (#22916)
1 parent d764b6a commit a1fc4bc

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

apps/web/app/api/social/og/image/route.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,31 @@ async function handler(req: NextRequest) {
3535
const imageType = searchParams.get("type");
3636

3737
try {
38-
const [calFontData, interFontData, interFontMediumData] = await Promise.all([
38+
const fontResults = await Promise.allSettled([
3939
fetch(new URL("/fonts/cal.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
4040
fetch(new URL("/fonts/Inter-Regular.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
4141
fetch(new URL("/fonts/Inter-Medium.ttf", WEBAPP_URL)).then((res) => res.arrayBuffer()),
4242
]);
43+
44+
const fonts: SatoriOptions["fonts"] = [];
45+
46+
if (fontResults[1].status === "fulfilled") {
47+
fonts.push({ name: "inter", data: fontResults[1].value, weight: 400 });
48+
}
49+
50+
if (fontResults[2].status === "fulfilled") {
51+
fonts.push({ name: "inter", data: fontResults[2].value, weight: 500 });
52+
}
53+
54+
if (fontResults[0].status === "fulfilled") {
55+
fonts.push({ name: "cal", data: fontResults[0].value, weight: 400 });
56+
fonts.push({ name: "cal", data: fontResults[0].value, weight: 600 });
57+
}
58+
4359
const ogConfig = {
4460
width: 1200,
4561
height: 630,
46-
fonts: [
47-
{ name: "inter", data: interFontData, weight: 400 },
48-
{ name: "inter", data: interFontMediumData, weight: 500 },
49-
{ name: "cal", data: calFontData, weight: 400 },
50-
{ name: "cal", data: calFontData, weight: 600 },
51-
] as SatoriOptions["fonts"],
62+
fonts,
5263
};
5364

5465
switch (imageType) {

0 commit comments

Comments
 (0)