Fix error when generating static make-less lens pages

This commit is contained in:
Sam Becker 2025-03-18 08:51:14 -05:00
parent dbedf5d1a2
commit 481d603475
3 changed files with 26 additions and 7 deletions

View File

@ -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<Lens[]>) | 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);
};
}

View File

@ -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);
};
}

View File

@ -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<Lens>) =>
parameterize(`${make ?? 'ANY'}-${model ?? 'ANY'}`);