diff --git a/app/lens/[make]/[model]/image/route.tsx b/app/lens/[make]/[model]/image/route.tsx index 3a165c06..e8ced2f0 100644 --- a/app/lens/[make]/[model]/image/route.tsx +++ b/app/lens/[make]/[model]/image/route.tsx @@ -12,18 +12,22 @@ import { STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES, IS_PRODUCTION, } from '@/app/config'; -import { getLensFromParams, Lens, LensProps } from '@/lens'; +import { + getLensFromParams, + Lens, + LensProps, + safelyGenerateLensStaticParams, +} from '@/lens'; import LensImageResponse from '@/image-response/LensImageResponse'; export let generateStaticParams: - (() => Promise<{ lens: Lens }[]>) | undefined = undefined; + (() => Promise) | undefined = undefined; if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) { generateStaticParams = async () => { const lenses = await getUniqueLenses(); - return lenses - .slice(0, GENERATE_STATIC_PARAMS_LIMIT) - .map(({ lens }) => ({ lens })); + return safelyGenerateLensStaticParams(lenses) + .slice(0, GENERATE_STATIC_PARAMS_LIMIT); }; } diff --git a/app/lens/[make]/[model]/page.tsx b/app/lens/[make]/[model]/page.tsx index 9e49ee35..2b506a7f 100644 --- a/app/lens/[make]/[model]/page.tsx +++ b/app/lens/[make]/[model]/page.tsx @@ -7,7 +7,13 @@ import { getUniqueLenses } from '@/photo/db/query'; import { generateMetaForLens } from '@/lens/meta'; import { getPhotosLensDataCached } from '@/lens/data'; import LensOverview from '@/lens/LensOverview'; -import { getLensFromParams, Lens, LensProps } from '@/lens'; +import { + getLensFromParams, + Lens, + LensProps, + safelyGenerateLensStaticParams, +} from '@/lens'; +import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; const getPhotosLensDataCachedCached = cache(( make: string | undefined, @@ -24,7 +30,8 @@ export let generateStaticParams: if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) { generateStaticParams = async () => { const lenses = await getUniqueLenses(); - return lenses.map(({ lens: { make, model } }) => ({ make, model })); + return safelyGenerateLensStaticParams(lenses) + .slice(0, GENERATE_STATIC_PARAMS_LIMIT); }; } diff --git a/src/lens/index.ts b/src/lens/index.ts index 4d3a6e8c..78a2fe17 100644 --- a/src/lens/index.ts +++ b/src/lens/index.ts @@ -46,6 +46,14 @@ export const getLensPhotoFromParams = async ( : { make, model, photoId }; }; +export const safelyGenerateLensStaticParams = ( + lenses: Lenses, +) => + lenses.map(({ lens: { make, model } }) => ({ + make: make ?? MISSING_FIELD, + model, + })); + // Support keys for make-only and model-only lens queries export const createLensKey = ({ make, model }: Partial) => parameterize(`${make ?? 'ANY'}-${model ?? 'ANY'}`);