fix(og): use import.meta.url and fetch instead of readFileSync for next/og fonts
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 1m0s
Build & Deploy / 🧪 QA (push) Successful in 1m44s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 1m0s
Build & Deploy / 🧪 QA (push) Successful in 1m44s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
This commit is contained in:
@@ -7,44 +7,31 @@ import { ImageResponse } from 'next/og';
|
|||||||
* Since we are using runtime = 'nodejs', we can read them from the filesystem.
|
* Since we are using runtime = 'nodejs', we can read them from the filesystem.
|
||||||
*/
|
*/
|
||||||
export async function getOgFonts() {
|
export async function getOgFonts() {
|
||||||
const boldFontPath = join(process.cwd(), 'public/fonts/Inter-Bold.ttf');
|
|
||||||
const regularFontPath = join(process.cwd(), 'public/fonts/Inter-Regular.ttf');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`[OG] Loading fonts: bold=${boldFontPath}, regular=${regularFontPath}`);
|
const boldFontData = await fetch(
|
||||||
const boldFontBuffer = readFileSync(boldFontPath);
|
new URL('../public/fonts/Inter-Bold.ttf', import.meta.url)
|
||||||
const regularFontBuffer = readFileSync(regularFontPath);
|
).then((res) => res.arrayBuffer());
|
||||||
|
|
||||||
// Satori (Vercel OG) strictly requires an ArrayBuffer, not a Node Buffer view.
|
const regularFontData = await fetch(
|
||||||
const boldFont = boldFontBuffer.buffer.slice(
|
new URL('../public/fonts/Inter-Regular.ttf', import.meta.url)
|
||||||
boldFontBuffer.byteOffset,
|
).then((res) => res.arrayBuffer());
|
||||||
boldFontBuffer.byteOffset + boldFontBuffer.byteLength,
|
|
||||||
);
|
|
||||||
const regularFont = regularFontBuffer.buffer.slice(
|
|
||||||
regularFontBuffer.byteOffset,
|
|
||||||
regularFontBuffer.byteOffset + regularFontBuffer.byteLength,
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`[OG] Fonts loaded successfully (${boldFont.byteLength} and ${regularFont.byteLength} bytes)`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'Inter',
|
name: 'Inter',
|
||||||
data: boldFont,
|
data: boldFontData,
|
||||||
weight: 700 as const,
|
|
||||||
style: 'normal' as const,
|
style: 'normal' as const,
|
||||||
|
weight: 700 as const,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Inter',
|
name: 'Inter',
|
||||||
data: regularFont,
|
data: regularFontData,
|
||||||
weight: 400 as const,
|
|
||||||
style: 'normal' as const,
|
style: 'normal' as const,
|
||||||
|
weight: 400 as const,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[OG] Failed to load fonts from ${process.cwd()}:`, error);
|
console.error(`[OG] Failed to load fonts:`, error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user