diff --git a/lib/og-helper.tsx b/lib/og-helper.tsx index 09c2103e1..b5fad6a69 100644 --- a/lib/og-helper.tsx +++ b/lib/og-helper.tsx @@ -5,7 +5,9 @@ import { join } from 'path'; * Loads the Inter fonts for use in Satori (Next.js OG Image generation). * Since we are using runtime = 'nodejs', we can read them from the filesystem. */ +let cachedFonts: any[] | null = null; export async function getOgFonts() { + if (cachedFonts) return cachedFonts; const boldFontPath = join(process.cwd(), 'public/fonts/Inter-Bold.woff'); const regularFontPath = join(process.cwd(), 'public/fonts/Inter-Regular.woff'); @@ -28,7 +30,7 @@ export async function getOgFonts() { `[OG] Fonts loaded successfully (${boldFont.byteLength} and ${regularFont.byteLength} bytes)`, ); - return [ + cachedFonts = [ { name: 'Inter', data: boldFont, @@ -42,28 +44,35 @@ export async function getOgFonts() { style: 'normal' as const, }, ]; + return cachedFonts; } catch (error) { console.error(`[OG] Failed to load fonts from ${process.cwd()}:`, error); return []; } } +let cachedBackground: string | null = null; export function getOgBackground() { + if (cachedBackground) return cachedBackground; try { const bgPath = join(process.cwd(), 'public/assets/photos/Etib_E-tib_Tiefbau_Guben_Netzanbindung_Energie-100.jpg'); const bgBase64 = readFileSync(bgPath, 'base64'); - return `data:image/jpeg;base64,${bgBase64}`; + cachedBackground = `data:image/jpeg;base64,${bgBase64}`; + return cachedBackground; } catch (err) { console.error('[OG] Failed to load background', err); return undefined; } } +let cachedLogo: string | null = null; export function getOgLogo() { + if (cachedLogo) return cachedLogo; try { const logoPath = join(process.cwd(), 'public/assets/logo-white.png'); const logoBase64 = readFileSync(logoPath, 'base64'); - return `data:image/png;base64,${logoBase64}`; + cachedLogo = `data:image/png;base64,${logoBase64}`; + return cachedLogo; } catch (err) { console.error('[OG] Failed to load logo', err); return undefined; diff --git a/package.json b/package.json index ded7ef3bc..117a9c82e 100644 --- a/package.json +++ b/package.json @@ -139,7 +139,7 @@ "prepare": "husky", "preinstall": "npx only-allow pnpm" }, - "version": "2.2.93", + "version": "2.2.94", "pnpm": { "onlyBuiltDependencies": [ "@parcel/watcher",