mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 19:15:30 -04:00
fix: load OG image fonts from @fontsource/inter instead of Google Fonts
Vercel's build infra was intermittently hitting ETIMEDOUT against fonts.googleapis.com, causing OG image generation errors during prerender. Ship the Inter .woff files with the function via outputFileTracingIncludes so the build is network-free. Also add turbopackIgnore hints on process.cwd() calls to silence an NFT warning that was over-tracing next.config.ts into the route bundle. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
import { cacheLife } from "next/cache";
|
||||
|
||||
// Load a Google Font from the Google Fonts API
|
||||
// Adapted from https://github.com/brianlovin/briOS/blob/f72dc33a11194de45c80337b22be4560da62ad7e/src/lib/og-utils.tsx#L32
|
||||
export async function loadGoogleFont(font: string, weight: number): Promise<ArrayBuffer> {
|
||||
"use cache";
|
||||
|
||||
const url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weight}`;
|
||||
|
||||
const cssResponse = await fetch(url, {
|
||||
next: {
|
||||
revalidate: 31_536_000, // 1 year
|
||||
},
|
||||
});
|
||||
const css = await cssResponse.text();
|
||||
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
||||
|
||||
if (resource) {
|
||||
const fontResponse = await fetch(resource[1], {
|
||||
next: {
|
||||
revalidate: 31_536_000, // 1 year
|
||||
},
|
||||
});
|
||||
if (fontResponse.status === 200) {
|
||||
cacheLife("max"); // cache indefinitely if successful
|
||||
return fontResponse.arrayBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Failed to load font: ${font} ${weight}`);
|
||||
}
|
||||
Reference in New Issue
Block a user