Fix error when generating static make-less lens pages
This commit is contained in:
parent
dbedf5d1a2
commit
481d603475
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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'}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user