From 9fae44744fbe5bb94028f2a92b57f1b8cd37c6ea Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Sat, 2 Nov 2024 20:31:08 -0700 Subject: [PATCH] generate og images at build time --- app/(post)/og/[id]/route.tsx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/(post)/og/[id]/route.tsx b/app/(post)/og/[id]/route.tsx index 800c9dc1..a8c4b614 100644 --- a/app/(post)/og/[id]/route.tsx +++ b/app/(post)/og/[id]/route.tsx @@ -1,34 +1,56 @@ +export const revalidate = 60; + import { ImageResponse } from "next/og"; import { getPosts } from "@/app/get-posts"; import { readFileSync } from "fs"; import { join } from "path"; +export async function generateStaticParams() { + return (await getPosts()).map(post => ({ id: post.id })); +} + // fonts const inter300 = readFileSync( join( process.cwd(), - "node_modules/@fontsource/inter/files/inter-latin-300-normal.woff" + "node_modules", + "@fontsource", + "inter", + "files", + "inter-latin-300-normal.woff" ) ); const inter500 = readFileSync( join( process.cwd(), - "node_modules/@fontsource/inter/files/inter-latin-500-normal.woff" + "node_modules", + "@fontsource", + "inter", + "files", + "inter-latin-500-normal.woff" ) ); const inter600 = readFileSync( join( process.cwd(), - "node_modules/@fontsource/inter/files/inter-latin-600-normal.woff" + "node_modules", + "@fontsource", + "inter", + "files", + "inter-latin-600-normal.woff" ) ); const robotoMono400 = readFileSync( join( process.cwd(), - "node_modules/@fontsource/roboto-mono/files/roboto-mono-latin-400-normal.woff" + "node_modules", + "@fontsource", + "roboto-mono", + "files", + "roboto-mono-latin-400-normal.woff" ) );