From 4887f93bfcbe8e81c26cf3d5f87ab3c9977c9209 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 19 Jan 2024 12:11:42 -0600 Subject: [PATCH] Generate static params for photo detail pages --- src/app/p/[photoId]/layout.tsx | 8 +++++++- src/photo/index.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/p/[photoId]/layout.tsx b/src/app/p/[photoId]/layout.tsx index 676c0c53..974ef37e 100644 --- a/src/app/p/[photoId]/layout.tsx +++ b/src/app/p/[photoId]/layout.tsx @@ -1,4 +1,5 @@ import { + GENERATE_STATIC_PARAMS_LIMIT, GRID_THUMBNAILS_TO_SHOW_MAX, descriptionForPhoto, titleForPhoto, @@ -12,8 +13,13 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached, getPhotosNearIdCached } from '@/cache'; +import { getPhotos } from '@/services/vercel-postgres'; + +export async function generateStaticParams() { + const photos = await getPhotos({ limit: GENERATE_STATIC_PARAMS_LIMIT }); + return photos.map(({ id }) => ({ photoId: id })); +} -export const runtime = 'edge'; interface PhotoProps { params: { photoId: string } diff --git a/src/photo/index.ts b/src/photo/index.ts index 05939f1f..664d4aba 100644 --- a/src/photo/index.ts +++ b/src/photo/index.ts @@ -11,6 +11,8 @@ import { import camelcaseKeys from 'camelcase-keys'; import type { Metadata } from 'next'; +export const GENERATE_STATIC_PARAMS_LIMIT = 1000; + export const PHOTO_LOAD_MULTIPLE_ROOT = process.env.NODE_ENV === 'development' ? 2 : 12; export const PHOTO_LOAD_MULTIPLE_GRID =