Add static optimization to category image routes

This commit is contained in:
Sam Becker 2025-01-27 20:55:39 -06:00
parent 46a1b0f743
commit cce2043fca
4 changed files with 74 additions and 2 deletions

View File

@ -9,6 +9,24 @@ import { FilmSimulation } from '@/simulation';
import { getIBMPlexMonoMedium } from '@/site/font';
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 '@/site/config';
export let generateStaticParams:
(() => Promise<{ simulation: FilmSimulation }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
generateStaticParams = async () => {
const simulations = await getUniqueFilmSimulations();
return simulations
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ simulation }) => ({ simulation }));
};
}
export async function GET(
_: Request,

View File

@ -8,7 +8,25 @@ import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import FocalLengthImageResponse from
'@/image-response/FocalLengthImageResponse';
import { getFocalLengthFromString } from '@/focal';
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 '@/site/config';
export let generateStaticParams:
(() => Promise<{ focal: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
generateStaticParams = async () => {
const focalLengths= await getUniqueFocalLengths();
return focalLengths
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ focal }) => ({ focal: formatFocalLength(focal)! }));
};
}
export async function GET(
_: Request,

View File

@ -1,5 +1,5 @@
import { getPhotosCached } from '@/photo/cache';
import { CameraProps, getCameraFromParams } from '@/camera';
import { Camera, CameraProps, getCameraFromParams } from '@/camera';
import {
IMAGE_OG_DIMENSION_SMALL,
MAX_PHOTOS_TO_SHOW_PER_TAG,
@ -8,6 +8,24 @@ import CameraImageResponse from '@/image-response/CameraImageResponse';
import { getIBMPlexMonoMedium } from '@/site/font';
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 '@/site/config';
export let generateStaticParams:
(() => Promise<{ camera: Camera }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
generateStaticParams = async () => {
const cameras = await getUniqueCameras();
return cameras
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ camera }) => ({ camera }));
};
}
export async function GET(
_: Request,

View File

@ -7,6 +7,24 @@ import TagImageResponse from '@/image-response/TagImageResponse';
import { getIBMPlexMonoMedium } from '@/site/font';
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 '@/site/config';
export let generateStaticParams:
(() => Promise<{ tag: string }[]>) | undefined = undefined;
if (STATICALLY_OPTIMIZED_PHOTO_CATEGORY_OG_IMAGES && IS_PRODUCTION) {
generateStaticParams = async () => {
const tags = await getUniqueTags();
return tags
.slice(0, GENERATE_STATIC_PARAMS_LIMIT)
.map(({ tag }) => ({ tag }));
};
}
export async function GET(
_: Request,