Refactor category-based config for static params

This commit is contained in:
Sam Becker 2025-03-18 09:34:12 -05:00
parent 72ba24690d
commit c6f28616c9
15 changed files with 28 additions and 31 deletions

View File

@ -11,7 +11,7 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueFilmSimulations } from '@/photo/db/query'; import { getUniqueFilmSimulations } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined; (() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined;

View File

@ -7,8 +7,9 @@ import { Metadata } from 'next/types';
import { cache } from 'react'; import { cache } from 'react';
import { PATH_ROOT } from '@/app/paths'; import { PATH_ROOT } from '@/app/paths';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosFilmSimulationDataCachedCached = const getPhotosFilmSimulationDataCachedCached =
cache(getPhotosFilmSimulationDataCached); cache(getPhotosFilmSimulationDataCached);

View File

@ -11,7 +11,7 @@ import FocalLengthImageResponse from
import { formatFocalLength, getFocalLengthFromString } from '@/focal'; import { formatFocalLength, getFocalLengthFromString } from '@/focal';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueFocalLengths } from '@/photo/db/query'; import { getUniqueFocalLengths } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ focal: string }[]>) | undefined = undefined; (() => Promise<{ focal: string }[]>) | undefined = undefined;

View File

@ -7,7 +7,7 @@ import { PATH_ROOT } from '@/app/paths';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import { cache } from 'react'; import { cache } from 'react';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosFocalDataCachedCached = cache((focal: number) => const getPhotosFocalDataCachedCached = cache((focal: number) =>

View File

@ -15,7 +15,7 @@ import {
safelyGenerateLensStaticParams, safelyGenerateLensStaticParams,
} from '@/lens'; } from '@/lens';
import LensImageResponse from '@/image-response/LensImageResponse'; import LensImageResponse from '@/image-response/LensImageResponse';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<Lens[]>) | undefined = undefined; (() => Promise<Lens[]>) | undefined = undefined;

View File

@ -12,7 +12,7 @@ import {
safelyGenerateLensStaticParams, safelyGenerateLensStaticParams,
} from '@/lens'; } from '@/lens';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
const getPhotosLensDataCachedCached = cache(( const getPhotosLensDataCachedCached = cache((
make: string | undefined, make: string | undefined,

View File

@ -9,7 +9,7 @@ import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueRecipes } from '@/photo/db/query'; import { getUniqueRecipes } from '@/photo/db/query';
import RecipeImageResponse from '@/image-response/RecipeImageResponse'; import RecipeImageResponse from '@/image-response/RecipeImageResponse';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ recipe: string }[]>) | undefined = undefined; (() => Promise<{ recipe: string }[]>) | undefined = undefined;

View File

@ -7,7 +7,7 @@ import { cache } from 'react';
import { generateMetaForRecipe } from '@/recipe'; import { generateMetaForRecipe } from '@/recipe';
import RecipeOverview from '@/recipe/RecipeOverview'; import RecipeOverview from '@/recipe/RecipeOverview';
import { getPhotosRecipeDataCached } from '@/recipe/data'; import { getPhotosRecipeDataCached } from '@/recipe/data';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosRecipeDataCachedCached = cache(getPhotosRecipeDataCached); const getPhotosRecipeDataCachedCached = cache(getPhotosRecipeDataCached);

View File

@ -10,7 +10,7 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueCameras } from '@/photo/db/query'; import { getUniqueCameras } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ camera: Camera }[]>) | undefined = undefined; (() => Promise<{ camera: Camera }[]>) | undefined = undefined;

View File

@ -6,7 +6,7 @@ import { getPhotosCameraDataCached } from '@/camera/data';
import CameraOverview from '@/camera/CameraOverview'; import CameraOverview from '@/camera/CameraOverview';
import { cache } from 'react'; import { cache } from 'react';
import { getUniqueCameras } from '@/photo/db/query'; import { getUniqueCameras } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosCameraDataCachedCached = cache(( const getPhotosCameraDataCachedCached = cache((

View File

@ -9,7 +9,7 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
import { getUniqueTags } from '@/photo/db/query'; import { getUniqueTags } from '@/photo/db/query';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ tag: string }[]>) | undefined = undefined; (() => Promise<{ tag: string }[]>) | undefined = undefined;

View File

@ -7,7 +7,7 @@ import { getPhotosTagDataCached } from '@/tag/data';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import { cache } from 'react'; import { cache } from 'react';
import { shouldGenerateStaticParamsForCategory } from '@/category'; import { shouldGenerateStaticParamsForCategory } from '@/app/config';
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db'; import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
const getPhotosTagDataCachedCached = cache((tag: string) => const getPhotosTagDataCachedCached = cache((tag: string) =>

View File

@ -2,7 +2,7 @@ import {
AI_AUTO_GENERATED_FIELDS_DEFAULT, AI_AUTO_GENERATED_FIELDS_DEFAULT,
parseAiAutoGeneratedFieldsString, parseAiAutoGeneratedFieldsString,
} from '@/photo/ai'; } from '@/photo/ai';
import { getOrderedCategoriesFromString } from '@/category'; import { CategoryKey, getOrderedCategoriesFromString } from '@/category';
import type { StorageType } from '@/platforms/storage'; import type { StorageType } from '@/platforms/storage';
import { makeUrlAbsolute, shortenUrl } from '@/utility/url'; import { makeUrlAbsolute, shortenUrl } from '@/utility/url';
@ -184,6 +184,17 @@ export const HAS_STATIC_OPTIMIZATION =
STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES || STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES ||
STATICALLY_OPTIMIZED_PHOTO_CATEGORIES || STATICALLY_OPTIMIZED_PHOTO_CATEGORIES ||
STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES; STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES;
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 PRESERVE_ORIGINAL_UPLOADS = export const PRESERVE_ORIGINAL_UPLOADS =
process.env.NEXT_PUBLIC_PRESERVE_ORIGINAL_UPLOADS === '1' || process.env.NEXT_PUBLIC_PRESERVE_ORIGINAL_UPLOADS === '1' ||
// Legacy environment variable name // Legacy environment variable name
@ -195,6 +206,7 @@ export const IMAGE_QUALITY =
export const BLUR_ENABLED = export const BLUR_ENABLED =
process.env.NEXT_PUBLIC_BLUR_DISABLED !== '1'; process.env.NEXT_PUBLIC_BLUR_DISABLED !== '1';
// VISUAL // VISUAL
export const DEFAULT_THEME = export const DEFAULT_THEME =

View File

@ -6,12 +6,6 @@ import { Lens, Lenses } from '@/lens';
import { Tags } from '@/tag'; import { Tags } from '@/tag';
import { FocalLengths } from '@/focal'; import { FocalLengths } from '@/focal';
import { Recipes } from '@/recipe'; 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 = [ const CATEGORY_KEYS = [
'cameras', 'cameras',
@ -22,9 +16,9 @@ const CATEGORY_KEYS = [
'focal-lengths', 'focal-lengths',
] as const; ] as const;
type CategoryKey = (typeof CATEGORY_KEYS)[number]; export type CategoryKey = (typeof CATEGORY_KEYS)[number];
type CategoryKeys = CategoryKey[]; export type CategoryKeys = CategoryKey[];
export const DEFAULT_CATEGORY_KEYS: CategoryKeys = [ export const DEFAULT_CATEGORY_KEYS: CategoryKeys = [
'tags', 'tags',
@ -33,16 +27,6 @@ export const DEFAULT_CATEGORY_KEYS: CategoryKeys = [
'films', '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 => export const getHiddenCategories = (keys: CategoryKeys): CategoryKeys =>
CATEGORY_KEYS.filter(key => !keys.includes(key)); CATEGORY_KEYS.filter(key => !keys.includes(key));