feat(og): migrate to co-located opengraph-image.tsx convention

This commit is contained in:
2026-02-17 11:57:46 +01:00
parent e2c9ec507f
commit 28053952ea
7 changed files with 143 additions and 72 deletions

View File

@@ -6,14 +6,36 @@ import { join } from "path";
* Since we are using runtime = 'nodejs', we can read them from the filesystem.
*/
export async function getOgFonts() {
const boldFontPath = join(
process.cwd(),
"apps/web/public/fonts/Inter-Bold.woff",
);
const regularFontPath = join(
process.cwd(),
"apps/web/public/fonts/Inter-Regular.woff",
);
// Use relative path from process.cwd() which usually is the monorepo root or apps/web
// We try both to be safe during different execution contexts (dev vs build vs runtime)
const pathsToTry = [
join(process.cwd(), "apps/web/public/fonts"),
join(process.cwd(), "public/fonts"),
];
let boldFontPath = "";
let regularFontPath = "";
for (const basePath of pathsToTry) {
const b = join(basePath, "Inter-Bold.woff");
const r = join(basePath, "Inter-Regular.woff");
try {
if (readFileSync(b) && readFileSync(r)) {
boldFontPath = b;
regularFontPath = r;
break;
}
} catch (e) {
continue;
}
}
if (!boldFontPath || !regularFontPath) {
console.error(
`[OG] Could not find fonts in either ${pathsToTry.join(" or ")}`,
);
return [];
}
try {
console.log(
@@ -40,7 +62,7 @@ export async function getOgFonts() {
},
];
} catch (error) {
console.error(`[OG] Failed to load fonts from ${process.cwd()}:`, error);
console.error(`[OG] Failed to load fonts:`, error);
return [];
}
}