Vercel/app/year/[year]/[photoId]/page.tsx
Sam Becker b3972a6032
Date-based photo sets (#276)
* Add 'recents' and 'years' categories

* Add recents and years visibility config

* Add fundamental recent/year queries

* Display initial date-based data in sidebar

* Adjust recents data type

* Remove date rage from sidebar footer

* Reformat recents/years in sidebar

* Organize years in grid

* Rename date -> year

* Add year-based views

* Split sidebar years into rows

* Add years to cmdk menu

* Localize 'years'

* Create /recents views

* Enable recents share modals

* Fix recents og image

* Statically optimize /recents image

* Don't statically optimize /recents page

* Update i18n

* Add recents to cmdk

* Suppress spinner for year badges

* Refactor sidebar height calculation

* Add recents to sitemap
2025-06-28 11:48:48 -05:00

87 lines
1.9 KiB
TypeScript

import {
RELATED_GRID_PHOTOS_TO_SHOW,
descriptionForPhoto,
titleForPhoto,
} from '@/photo';
import { Metadata } from 'next/types';
import { redirect } from 'next/navigation';
import {
PATH_ROOT,
absolutePathForPhoto,
absolutePathForPhotoImage,
} from '@/app/paths';
import PhotoDetailPage from '@/photo/PhotoDetailPage';
import {
getPhotosMetaCached,
getPhotosNearIdCached,
} from '@/photo/cache';
import { cache } from 'react';
const getPhotosNearIdCachedCached = cache((photoId: string, year: string) =>
getPhotosNearIdCached(
photoId,
{ year, limit: RELATED_GRID_PHOTOS_TO_SHOW + 2 },
));
interface PhotoYearProps {
params: Promise<{ photoId: string, year: string }>
}
export async function generateMetadata({
params,
}: PhotoYearProps): Promise<Metadata> {
const { photoId, year } = await params;
const { photo } = await getPhotosNearIdCachedCached(photoId, year);
if (!photo) { return {}; }
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo, year });
return {
title,
description: descriptionHtml,
openGraph: {
title,
images,
description,
url,
},
twitter: {
title,
description,
images,
card: 'summary_large_image',
},
};
}
export default async function PhotoYearPage({
params,
}: PhotoYearProps) {
const { photoId, year } = await params;
const { photo, photos, photosGrid, indexNumber } =
await getPhotosNearIdCachedCached(photoId, year);
if (!photo) { redirect(PATH_ROOT); }
const { count, dateRange } = await getPhotosMetaCached({ year: year });
return (
<PhotoDetailPage {...{
photo,
photos,
photosGrid,
year,
indexNumber,
count,
dateRange,
}} />
);
}