From 3a5ed478fc43d3c6f3a78eff509d6667e54f6a6c Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Wed, 20 Sep 2023 23:37:04 -0500 Subject: [PATCH] Generate static params for tagged photos --- src/app/(static)/t/[tag]/[photoId]/layout.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/(static)/t/[tag]/[photoId]/layout.tsx b/src/app/(static)/t/[tag]/[photoId]/layout.tsx index 8cdb0448..06bad5eb 100644 --- a/src/app/(static)/t/[tag]/[photoId]/layout.tsx +++ b/src/app/(static)/t/[tag]/[photoId]/layout.tsx @@ -7,8 +7,21 @@ import { redirect } from 'next/navigation'; import { absolutePathForPhoto, absolutePathForPhotoImage } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached, getPhotosCached } from '@/cache'; +import { getPhotos, getUniqueTags } from '@/services/postgres'; -export const runtime = 'edge'; +export async function generateStaticParams() { + const params: { params: { photoId: string, tag: string }}[] = []; + + const tags = await getUniqueTags(); + tags.forEach(async tag => { + const photos = await getPhotos({ tag }); + params.push(...photos.map(photo => ({ + params: { photoId: photo.id, tag }, + }))); + }); + + return params; +} export async function generateMetadata({ params: { photoId, tag },