Use @fontsource/inter woff for OG renderer instead of broken TTF download

The Inter SemiBold TTF from GitHub was an HTML error page. Switch to
loading inter-latin-600-normal.woff from @fontsource/inter in
node_modules — always available, always valid, and Satori supports
woff natively.
This commit is contained in:
Ryan Malloy 2026-02-14 13:30:43 -07:00
parent db2ecf32c4
commit 7d5d1b2d31
4 changed files with 26 additions and 1467 deletions

View File

@ -18,6 +18,7 @@
"@codemirror/language": "^6.10.0",
"@codemirror/state": "^6.5.0",
"@codemirror/view": "^6.35.0",
"@fontsource/inter": "^5.2.8",
"@iconify-json/lucide": "^1.2.90",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0",
@ -1706,6 +1707,15 @@
"node": ">=18"
}
},
"node_modules/@fontsource/inter": {
"version": "5.2.8",
"resolved": "https://registry.npmjs.org/@fontsource/inter/-/inter-5.2.8.tgz",
"integrity": "sha512-P6r5WnJoKiNVV+zvW2xM13gNdFhAEpQ9dQJHt3naLvfg+LkF2ldgSLiF4T41lf1SQCM9QmkqPTn4TH568IRagg==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@iconify-json/lucide": {
"version": "1.2.90",
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.2.90.tgz",

View File

@ -19,6 +19,7 @@
"@codemirror/language": "^6.10.0",
"@codemirror/state": "^6.5.0",
"@codemirror/view": "^6.35.0",
"@fontsource/inter": "^5.2.8",
"@iconify-json/lucide": "^1.2.90",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0",

File diff suppressed because one or more lines are too long

View File

@ -10,22 +10,21 @@ interface OgImageProps {
}
function loadFont(): ArrayBuffer {
// In prod: dist/client/fonts/ In dev: public/fonts/
const candidates = [
join(process.cwd(), 'dist', 'client', 'fonts', 'Inter-SemiBold.ttf'),
join(process.cwd(), 'public', 'fonts', 'Inter-SemiBold.ttf'),
];
for (const path of candidates) {
try {
const buf = readFileSync(path);
// Node.js Buffers share a pooled ArrayBuffer — slice to get a
// standalone copy so Satori's OpenType parser starts at byte 0.
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
} catch {
// try next
}
}
throw new Error('Inter-SemiBold.ttf not found');
// Load Inter SemiBold (weight 600) from @fontsource/inter in node_modules.
// This is always available because it's a production dependency.
// Satori supports woff format natively.
const fontPath = join(
process.cwd(),
'node_modules',
'@fontsource',
'inter',
'files',
'inter-latin-600-normal.woff'
);
const buf = readFileSync(fontPath);
// Node.js Buffers share a pooled ArrayBuffer — slice to get a
// standalone copy so Satori's OpenType parser starts at byte 0.
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
let fontData: ArrayBuffer | null = null;