From 3570e10e9fe842799d0964a69b22052c50e82be3 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 29 Apr 2024 14:33:47 -0500 Subject: [PATCH] Statically generate og images --- src/app/p/[photoId]/image/route.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app/p/[photoId]/image/route.tsx b/src/app/p/[photoId]/image/route.tsx index 965db7df..63ca0ff6 100644 --- a/src/app/p/[photoId]/image/route.tsx +++ b/src/app/p/[photoId]/image/route.tsx @@ -4,6 +4,19 @@ import PhotoImageResponse from '@/image-response/PhotoImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; +import { STATICALLY_OPTIMIZED } from '@/site/config'; +import { getPhotoIds } from '@/services/vercel-postgres'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo'; + +export let generateStaticParams: + (() => Promise<{ photoId: string }[]>) | undefined = undefined; + +if (STATICALLY_OPTIMIZED) { + generateStaticParams = async () => { + const photos = await getPhotoIds({ limit: GENERATE_STATIC_PARAMS_LIMIT }); + return photos.map(photoId => ({ photoId })); + }; +} export async function GET( _: Request,