Refactor category-based config for static params
This commit is contained in:
parent
72ba24690d
commit
c6f28616c9
@ -11,7 +11,7 @@ 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 { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined;
|
||||
|
||||
@ -7,8 +7,9 @@ import { Metadata } from 'next/types';
|
||||
import { cache } from 'react';
|
||||
import { PATH_ROOT } from '@/app/paths';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
|
||||
const getPhotosFilmSimulationDataCachedCached =
|
||||
cache(getPhotosFilmSimulationDataCached);
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import FocalLengthImageResponse from
|
||||
import { formatFocalLength, getFocalLengthFromString } from '@/focal';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
import { getUniqueFocalLengths } from '@/photo/db/query';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<{ focal: string }[]>) | undefined = undefined;
|
||||
|
||||
@ -7,7 +7,7 @@ import { PATH_ROOT } from '@/app/paths';
|
||||
import type { Metadata } from 'next';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { cache } from 'react';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
|
||||
const getPhotosFocalDataCachedCached = cache((focal: number) =>
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
safelyGenerateLensStaticParams,
|
||||
} from '@/lens';
|
||||
import LensImageResponse from '@/image-response/LensImageResponse';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<Lens[]>) | undefined = undefined;
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
safelyGenerateLensStaticParams,
|
||||
} from '@/lens';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
const getPhotosLensDataCachedCached = cache((
|
||||
make: string | undefined,
|
||||
|
||||
@ -9,7 +9,7 @@ import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
import { getUniqueRecipes } from '@/photo/db/query';
|
||||
import RecipeImageResponse from '@/image-response/RecipeImageResponse';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<{ recipe: string }[]>) | undefined = undefined;
|
||||
|
||||
@ -7,7 +7,7 @@ import { cache } from 'react';
|
||||
import { generateMetaForRecipe } from '@/recipe';
|
||||
import RecipeOverview from '@/recipe/RecipeOverview';
|
||||
import { getPhotosRecipeDataCached } from '@/recipe/data';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
|
||||
const getPhotosRecipeDataCachedCached = cache(getPhotosRecipeDataCached);
|
||||
|
||||
@ -10,7 +10,7 @@ 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 { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<{ camera: Camera }[]>) | undefined = undefined;
|
||||
|
||||
@ -6,7 +6,7 @@ import { getPhotosCameraDataCached } from '@/camera/data';
|
||||
import CameraOverview from '@/camera/CameraOverview';
|
||||
import { cache } from 'react';
|
||||
import { getUniqueCameras } from '@/photo/db/query';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
|
||||
const getPhotosCameraDataCachedCached = cache((
|
||||
|
||||
@ -9,7 +9,7 @@ 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 { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
|
||||
export let generateStaticParams:
|
||||
(() => Promise<{ tag: string }[]>) | undefined = undefined;
|
||||
|
||||
@ -7,7 +7,7 @@ import { getPhotosTagDataCached } from '@/tag/data';
|
||||
import type { Metadata } from 'next';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { cache } from 'react';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/category';
|
||||
import { shouldGenerateStaticParamsForCategory } from '@/app/config';
|
||||
import { GENERATE_STATIC_PARAMS_LIMIT } from '@/photo/db';
|
||||
|
||||
const getPhotosTagDataCachedCached = cache((tag: string) =>
|
||||
|
||||
@ -2,7 +2,7 @@ import {
|
||||
AI_AUTO_GENERATED_FIELDS_DEFAULT,
|
||||
parseAiAutoGeneratedFieldsString,
|
||||
} from '@/photo/ai';
|
||||
import { getOrderedCategoriesFromString } from '@/category';
|
||||
import { CategoryKey, getOrderedCategoriesFromString } from '@/category';
|
||||
import type { StorageType } from '@/platforms/storage';
|
||||
import { makeUrlAbsolute, shortenUrl } from '@/utility/url';
|
||||
|
||||
@ -184,6 +184,17 @@ export const HAS_STATIC_OPTIMIZATION =
|
||||
STATICALLY_OPTIMIZED_PHOTO_OG_IMAGES ||
|
||||
STATICALLY_OPTIMIZED_PHOTO_CATEGORIES ||
|
||||
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 =
|
||||
process.env.NEXT_PUBLIC_PRESERVE_ORIGINAL_UPLOADS === '1' ||
|
||||
// Legacy environment variable name
|
||||
@ -195,6 +206,7 @@ export const IMAGE_QUALITY =
|
||||
export const BLUR_ENABLED =
|
||||
process.env.NEXT_PUBLIC_BLUR_DISABLED !== '1';
|
||||
|
||||
|
||||
// VISUAL
|
||||
|
||||
export const DEFAULT_THEME =
|
||||
|
||||
@ -6,12 +6,6 @@ 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 = [
|
||||
'cameras',
|
||||
@ -22,9 +16,9 @@ const CATEGORY_KEYS = [
|
||||
'focal-lengths',
|
||||
] 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 = [
|
||||
'tags',
|
||||
@ -33,16 +27,6 @@ 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));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user