Statically generate tag-based share paths

This commit is contained in:
Sam Becker 2023-09-21 20:38:51 -05:00
parent 96f8c18893
commit c213711e7a
2 changed files with 21 additions and 2 deletions

View File

@ -1,8 +1,21 @@
import { getPhotoCached } from '@/cache';
import PhotoShareModal from '@/photo/PhotoShareModal';
import { getPhotos, getUniqueTags } from '@/services/postgres';
import { redirect } from 'next/navigation';
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 default async function Share({
params: { photoId, tag },

View File

@ -1,10 +1,16 @@
import { getPhotosCached } from '@/cache';
import SiteGrid from '@/components/SiteGrid';
import PhotoGrid from '@/photo/PhotoGrid';
import { getUniqueTags } from '@/services/postgres';
import TagHeader from '@/tag/TagHeader';
import TagShareModal from '@/tag/TagShareModal';
export const runtime = 'edge';
export async function generateStaticParams() {
const tags = await getUniqueTags();
return tags.map(tag => ({
params: { tag },
}));
}
export default async function Share({
params: { tag },