Standardize static category page generation

This commit is contained in:
Sam Becker 2025-03-18 09:12:50 -05:00
parent 481d603475
commit e317d44593
13 changed files with 71 additions and 65 deletions

View File

@ -11,20 +11,17 @@ 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 '@/app/config';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('films', 'image')) {
generateStaticParams = async () => {
const simulations = await getUniqueFilmSimulations();
return simulations
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ simulation }) => ({ simulation }));
.map(({ simulation }) => ({ simulation }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -2,24 +2,25 @@ import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { getUniqueFilmSimulations } from '@/photo/db/query';
import { FilmSimulation, generateMetaForFilmSimulation } from '@/simulation';
import FilmSimulationOverview from '@/simulation/FilmSimulationOverview';
import { IS_PRODUCTION } from '@/app/config';
import { getPhotosFilmSimulationDataCached } from '@/simulation/data';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { Metadata } from 'next/types';
import { cache } from 'react';
import { PATH_ROOT } from '@/app/paths';
import { redirect } from 'next/navigation';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosFilmSimulationDataCachedCached =
cache(getPhotosFilmSimulationDataCached);
export let generateStaticParams:
(() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('films', 'page')) {
generateStaticParams = async () => {
const simulations = await getUniqueFilmSimulations();
return simulations.map(({ simulation }) => ({ simulation }));
return simulations
.map(({ simulation }) => ({ simulation }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -11,20 +11,17 @@ import FocalLengthImageResponse from
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 '@/app/config';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<{ focal: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('focal-lengths', 'image')) {
generateStaticParams = async () => {
const focalLengths= await getUniqueFocalLengths();
return focalLengths
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ focal }) => ({ focal: formatFocalLength(focal)! }));
.map(({ focal }) => ({ focal: formatFocalLength(focal)! }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -2,13 +2,13 @@ import { generateMetaForFocalLength, getFocalLengthFromString } from '@/focal';
import FocalLengthOverview from '@/focal/FocalLengthOverview';
import { getPhotosFocalLengthDataCached } from '@/focal/data';
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { IS_PRODUCTION } from '@/app/config';
import { getUniqueFocalLengths } from '@/photo/db/query';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { PATH_ROOT } from '@/app/paths';
import type { Metadata } from 'next';
import { redirect } from 'next/navigation';
import { cache } from 'react';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosFocalDataCachedCached = cache((focal: number) =>
getPhotosFocalLengthDataCached({
@ -19,10 +19,12 @@ const getPhotosFocalDataCachedCached = cache((focal: number) =>
export let generateStaticParams:
(() => Promise<{ focal: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('focal-lengths', 'page')) {
generateStaticParams = async () => {
const focalLengths = await getUniqueFocalLengths();
return focalLengths.map(({ focal }) => ({ focal: focal.toString() }));
return focalLengths
.map(({ focal }) => ({ focal: focal.toString() }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -8,10 +8,6 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueLenses } from '@/photo/db/query';
import {
STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES,
IS_PRODUCTION,
} from '@/app/config';
import {
getLensFromParams,
Lens,
@ -19,11 +15,12 @@ import {
safelyGenerateLensStaticParams,
} from '@/lens';
import LensImageResponse from '@/image-response/LensImageResponse';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<Lens[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('lenses', 'image')) {
generateStaticParams = async () => {
const lenses = await getUniqueLenses();
return safelyGenerateLensStaticParams(lenses)

View File

@ -1,8 +1,6 @@
import { Metadata } from 'next/types';
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { cache } from 'react';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { IS_PRODUCTION } from '@/app/config';
import { getUniqueLenses } from '@/photo/db/query';
import { generateMetaForLens } from '@/lens/meta';
import { getPhotosLensDataCached } from '@/lens/data';
@ -14,6 +12,7 @@ import {
safelyGenerateLensStaticParams,
} from '@/lens';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
const getPhotosLensDataCachedCached = cache((
make: string | undefined,
@ -27,7 +26,7 @@ const getPhotosLensDataCachedCached = cache((
export let generateStaticParams:
(() => Promise<Lens[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('lenses', 'page')) {
generateStaticParams = async () => {
const lenses = await getUniqueLenses();
return safelyGenerateLensStaticParams(lenses)

View File

@ -8,21 +8,18 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueRecipes } from '@/photo/db/query';
import {
STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES,
IS_PRODUCTION,
} from '@/app/config';
import RecipeImageResponse from '@/image-response/RecipeImageResponse';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<{ recipe: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('recipes', 'image')) {
generateStaticParams = async () => {
const recipes = await getUniqueRecipes();
return recipes
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ recipe }) => ({ recipe }));
.map(({ recipe }) => ({ recipe }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -1,7 +1,5 @@
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { getUniqueRecipes } from '@/photo/db/query';
import { IS_PRODUCTION } from '@/app/config';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { PATH_ROOT } from '@/app/paths';
import type { Metadata } from 'next';
import { redirect } from 'next/navigation';
@ -9,16 +7,20 @@ import { cache } from 'react';
import { generateMetaForRecipe } from '@/recipe';
import RecipeOverview from '@/recipe/RecipeOverview';
import { getPhotosRecipeDataCached } from '@/recipe/data';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosRecipeDataCachedCached = cache(getPhotosRecipeDataCached);
export let generateStaticParams:
(() => Promise<{ recipe: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('recipes', 'page')) {
generateStaticParams = async () => {
const recipes = await getUniqueRecipes();
return recipes.map(({ recipe }) => ({ recipe }));
return recipes
.map(({ recipe }) => ({ recipe }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -10,20 +10,17 @@ 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 '@/app/config';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<{ camera: Camera }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('cameras', 'image')) {
generateStaticParams = async () => {
const cameras = await getUniqueCameras();
return cameras
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ camera }) => ({ camera }));
.map(({ camera }) => ({ camera }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -5,9 +5,9 @@ import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { getPhotosCameraDataCached } from '@/camera/data';
import CameraOverview from '@/camera/CameraOverview';
import { cache } from 'react';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { IS_PRODUCTION } from '@/app/config';
import { getUniqueCameras } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosCameraDataCachedCached = cache((
make: string,
@ -21,10 +21,12 @@ const getPhotosCameraDataCachedCached = cache((
export let generateStaticParams:
(() => Promise<Camera[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('cameras', 'page')) {
generateStaticParams = async () => {
const cameras = await getUniqueCameras();
return cameras.map(({ camera: { make, model } }) => ({ make, model }));
return cameras
.map(({ camera: { make, model } }) => ({ make, model }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -9,20 +9,17 @@ 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 '@/app/config';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
export let generateStaticParams:
(() => Promise<{ tag: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('tags', 'image')) {
generateStaticParams = async () => {
const tags = await getUniqueTags();
return tags
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ tag }) => ({ tag }));
.map(({ tag }) => ({ tag }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -1,7 +1,5 @@
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
import { getUniqueTags } from '@/photo/db/query';
import { IS_PRODUCTION } from '@/app/config';
import { STATICALLY_OPTIMIZED_PHOTO_CATEGORIES } from '@/app/config';
import { PATH_ROOT } from '@/app/paths';
import { generateMetaForTag } from '@/tag';
import TagOverview from '@/tag/TagOverview';
@ -9,6 +7,8 @@ import { getPhotosTagDataCached } from '@/tag/data';
import type { Metadata } from 'next';
import { redirect } from 'next/navigation';
import { cache } from 'react';
import { shouldGenerateStaticParamsForCategory } from '@/photo/set';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosTagDataCachedCached = cache((tag: string) =>
getPhotosTagDataCached({ tag, limit: INFINITE_SCROLL_GRID_INITIAL}));
@ -16,10 +16,12 @@ const getPhotosTagDataCachedCached = cache((tag: string) =>
export let generateStaticParams:
(() => Promise<{ tag: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORIES && IS_PRODUCTION) {
if (shouldGenerateStaticParamsForCategory('tags', 'page')) {
generateStaticParams = async () => {
const tags = await getUniqueTags();
return tags.map(({ tag }) => ({ tag }));
return tags
.map(({ tag }) => ({ tag }))
.slice(0, GENERATE_STATIC_PARAMS_LIMIT);
};
}

View File

@ -6,11 +6,17 @@ import { Lens, Lenses } from '@/lens';
import { Tags } from '@/tag';
import { FocalLengths } from '@/focal';
import { Recipes } from '@/recipe';
import {
CATEGORY_VISIBILITY,
IS_PRODUCTION,
STATICALLY_OPTIMIZED_PHOTO_CATEGORIES,
STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES,
} from '@/app/config';
const CATEGORY_KEYS = [
'tags',
'cameras',
'lenses',
'tags',
'recipes',
'films',
'focal-lengths',
@ -27,6 +33,16 @@ export const DEFAULT_CATEGORY_KEYS: CategoryKeys = [
'films',
];
export const shouldGenerateStaticParamsForCategory = (
key: CategoryKey,
type: 'page' | 'image',
): boolean =>
CATEGORY_VISIBILITY.includes(key) &&
IS_PRODUCTION && (
(type === 'page' && STATICALLY_OPTIMIZED_PHOTO_CATEGORIES) ||
(type === 'image' && STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES)
);
export const getHiddenCategories = (keys: CategoryKeys): CategoryKeys =>
CATEGORY_KEYS.filter(key => !keys.includes(key));