Vercel/app/template-image/route.tsx
Sam Becker d7fbc8bd68
Configurable photo sort order (#277)
* Introduce configurable photo sort order

* Fix recents image pre-rendering

* Refine sort order config

* Store sort order in client state

* Add core views to support sort

* Separate sort and priority preferences

* Consolidate imports, add lint rule

* Refine photo sorting documentation

* Update README sort text

* Finalize sort config
2025-06-29 21:05:13 -05:00

45 lines
1.2 KiB
TypeScript

import { getPhotosCached } from '@/photo/cache';
import {
GRID_OG_DIMENSION,
MAX_PHOTOS_TO_SHOW_TEMPLATE,
} from '@/image-response';
import TemplateImageResponse from
'@/image-response/TemplateImageResponse';
import { getIBMPlexMono } from '@/app/font';
import { ImageResponse } from 'next/og';
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
import { isNextImageReadyBasedOnPhotos } from '@/photo';
export async function GET() {
const [
photos,
{ fontFamily, fonts },
headers,
] = await Promise.all([
getPhotosCached({
sortWithPriority: true,
limit: MAX_PHOTOS_TO_SHOW_TEMPLATE,
}).catch(() => []),
getIBMPlexMono(),
getImageResponseCacheControlHeaders(),
]);
const { width, height } = GRID_OG_DIMENSION;
// Make sure next/image can be reached from absolute urls,
// which may not exist on first pre-render
const isNextImageReady = await isNextImageReadyBasedOnPhotos(photos);
return new ImageResponse(
(
<TemplateImageResponse {...{
photos: isNextImageReady ? photos : [],
width,
height,
fontFamily,
}}/>
),
{ width, height, fonts, headers },
);
}