diff --git a/src/app/film/[simulation]/image/route.tsx b/src/app/film/[simulation]/image/route.tsx index dc493b34..62cb4996 100644 --- a/src/app/film/[simulation]/image/route.tsx +++ b/src/app/film/[simulation]/image/route.tsx @@ -9,6 +9,24 @@ import { FilmSimulation } from '@/simulation'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; +import { getUniqueFilmSimulations } from '@/photo/db/query'; +import { + STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES, + IS_PRODUCTION, +} from '@/site/config'; + +export let generateStaticParams: + (() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined; + +if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) { + generateStaticParams = async () => { + const simulations = await getUniqueFilmSimulations(); + return simulations + .slice(0, GENERATE_STATIC_PARAMS_LIMIT) + .map(({ simulation }) => ({ simulation })); + }; +} export async function GET( _: Request, diff --git a/src/app/focal/[focal]/image/route.tsx b/src/app/focal/[focal]/image/route.tsx index fd18e94c..44cc1558 100644 --- a/src/app/focal/[focal]/image/route.tsx +++ b/src/app/focal/[focal]/image/route.tsx @@ -8,7 +8,25 @@ import { ImageResponse } from 'next/og'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import FocalLengthImageResponse from '@/image-response/FocalLengthImageResponse'; -import { getFocalLengthFromString } from '@/focal'; +import { formatFocalLength, getFocalLengthFromString } from '@/focal'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; +import { getUniqueFocalLengths } from '@/photo/db/query'; +import { + STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES, + IS_PRODUCTION, +} from '@/site/config'; + +export let generateStaticParams: + (() => Promise<{ focal: string }[]>) | undefined = undefined; + +if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) { + generateStaticParams = async () => { + const focalLengths= await getUniqueFocalLengths(); + return focalLengths + .slice(0, GENERATE_STATIC_PARAMS_LIMIT) + .map(({ focal }) => ({ focal: formatFocalLength(focal)! })); + }; +} export async function GET( _: Request, diff --git a/src/app/shot-on/[make]/[model]/image/route.tsx b/src/app/shot-on/[make]/[model]/image/route.tsx index 59b81f0f..fce1c7ac 100644 --- a/src/app/shot-on/[make]/[model]/image/route.tsx +++ b/src/app/shot-on/[make]/[model]/image/route.tsx @@ -1,5 +1,5 @@ import { getPhotosCached } from '@/photo/cache'; -import { CameraProps, getCameraFromParams } from '@/camera'; +import { Camera, CameraProps, getCameraFromParams } from '@/camera'; import { IMAGE_OG_DIMENSION_SMALL, MAX_PHOTOS_TO_SHOW_PER_TAG, @@ -8,6 +8,24 @@ import CameraImageResponse from '@/image-response/CameraImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; +import { getUniqueCameras } from '@/photo/db/query'; +import { + STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES, + IS_PRODUCTION, +} from '@/site/config'; + +export let generateStaticParams: + (() => Promise<{ camera: Camera }[]>) | undefined = undefined; + +if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) { + generateStaticParams = async () => { + const cameras = await getUniqueCameras(); + return cameras + .slice(0, GENERATE_STATIC_PARAMS_LIMIT) + .map(({ camera }) => ({ camera })); + }; +} export async function GET( _: Request, diff --git a/src/app/tag/[tag]/image/route.tsx b/src/app/tag/[tag]/image/route.tsx index c5b16ae5..80e11bb1 100644 --- a/src/app/tag/[tag]/image/route.tsx +++ b/src/app/tag/[tag]/image/route.tsx @@ -7,6 +7,24 @@ import TagImageResponse from '@/image-response/TagImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; +import { getUniqueTags } from '@/photo/db/query'; +import { + STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES, + IS_PRODUCTION, +} from '@/site/config'; + +export let generateStaticParams: + (() => Promise<{ tag: string }[]>) | undefined = undefined; + +if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) { + generateStaticParams = async () => { + const tags = await getUniqueTags(); + return tags + .slice(0, GENERATE_STATIC_PARAMS_LIMIT) + .map(({ tag }) => ({ tag })); + }; +} export async function GET( _: Request,