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:
parent
db2ecf32c4
commit
7d5d1b2d31
10
frontend/package-lock.json
generated
10
frontend/package-lock.json
generated
@ -18,6 +18,7 @@
|
|||||||
"@codemirror/language": "^6.10.0",
|
"@codemirror/language": "^6.10.0",
|
||||||
"@codemirror/state": "^6.5.0",
|
"@codemirror/state": "^6.5.0",
|
||||||
"@codemirror/view": "^6.35.0",
|
"@codemirror/view": "^6.35.0",
|
||||||
|
"@fontsource/inter": "^5.2.8",
|
||||||
"@iconify-json/lucide": "^1.2.90",
|
"@iconify-json/lucide": "^1.2.90",
|
||||||
"@lezer/highlight": "^1.2.0",
|
"@lezer/highlight": "^1.2.0",
|
||||||
"@lezer/lr": "^1.4.0",
|
"@lezer/lr": "^1.4.0",
|
||||||
@ -1706,6 +1707,15 @@
|
|||||||
"node": ">=18"
|
"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": {
|
"node_modules/@iconify-json/lucide": {
|
||||||
"version": "1.2.90",
|
"version": "1.2.90",
|
||||||
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.2.90.tgz",
|
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.2.90.tgz",
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
"@codemirror/language": "^6.10.0",
|
"@codemirror/language": "^6.10.0",
|
||||||
"@codemirror/state": "^6.5.0",
|
"@codemirror/state": "^6.5.0",
|
||||||
"@codemirror/view": "^6.35.0",
|
"@codemirror/view": "^6.35.0",
|
||||||
|
"@fontsource/inter": "^5.2.8",
|
||||||
"@iconify-json/lucide": "^1.2.90",
|
"@iconify-json/lucide": "^1.2.90",
|
||||||
"@lezer/highlight": "^1.2.0",
|
"@lezer/highlight": "^1.2.0",
|
||||||
"@lezer/lr": "^1.4.0",
|
"@lezer/lr": "^1.4.0",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -10,22 +10,21 @@ interface OgImageProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadFont(): ArrayBuffer {
|
function loadFont(): ArrayBuffer {
|
||||||
// In prod: dist/client/fonts/ In dev: public/fonts/
|
// Load Inter SemiBold (weight 600) from @fontsource/inter in node_modules.
|
||||||
const candidates = [
|
// This is always available because it's a production dependency.
|
||||||
join(process.cwd(), 'dist', 'client', 'fonts', 'Inter-SemiBold.ttf'),
|
// Satori supports woff format natively.
|
||||||
join(process.cwd(), 'public', 'fonts', 'Inter-SemiBold.ttf'),
|
const fontPath = join(
|
||||||
];
|
process.cwd(),
|
||||||
for (const path of candidates) {
|
'node_modules',
|
||||||
try {
|
'@fontsource',
|
||||||
const buf = readFileSync(path);
|
'inter',
|
||||||
// Node.js Buffers share a pooled ArrayBuffer — slice to get a
|
'files',
|
||||||
// standalone copy so Satori's OpenType parser starts at byte 0.
|
'inter-latin-600-normal.woff'
|
||||||
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
);
|
||||||
} catch {
|
const buf = readFileSync(fontPath);
|
||||||
// try next
|
// 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);
|
||||||
throw new Error('Inter-SemiBold.ttf not found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let fontData: ArrayBuffer | null = null;
|
let fontData: ArrayBuffer | null = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user