* Make /db top-level module * Create Album type * Pin pnpm version * Generalize query modules * Finalize album postgres data type * Remove temp albums prop * Create basic album primitives * Fix temporary album bugs * Add albums to sidebar * Disambiguate string date utilities * Localize album language * Add album join option to core photo queries * Tweak album icon placement * Add album photo detail page * Refine Album data model * Display album subhead when available * Generate album og images * Finalize album share modal * Add albums to sitemap * Statically pre-render albums * Display tags on albums * Add albums to cmd-k menu * Handle album tag overflow * Stop truncating album subheads * Create core admin album views * Make albums editable * Create/edit albums on photo save, add delete album
98 lines
2.3 KiB
TypeScript
98 lines
2.3 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/path';
|
|
import PhotoDetailPage from '@/photo/PhotoDetailPage';
|
|
import { getPhotosMetaCached, getPhotosNearIdCached } from '@/photo/cache';
|
|
import { cache } from 'react';
|
|
import { getAlbumFromSlug } from '@/album/query';
|
|
import { Album } from '@/album';
|
|
|
|
const getPhotosNearIdCachedCached = cache((photoId: string, album: Album) =>
|
|
getPhotosNearIdCached(
|
|
photoId,
|
|
{ album, limit: RELATED_GRID_PHOTOS_TO_SHOW + 2 },
|
|
));
|
|
|
|
interface PhotoTagProps {
|
|
params: Promise<{ photoId: string, album: string }>
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: PhotoTagProps): Promise<Metadata> {
|
|
const { photoId, album: albumFromParams } = await params;
|
|
|
|
const albumSlug = decodeURIComponent(albumFromParams);
|
|
|
|
const album = await getAlbumFromSlug(albumSlug);
|
|
|
|
if (!album) { return {}; }
|
|
|
|
const { photo } = await getPhotosNearIdCachedCached(photoId, album);
|
|
|
|
if (!photo) { return {}; }
|
|
|
|
const title = titleForPhoto(photo);
|
|
const description = descriptionForPhoto(photo);
|
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
|
const images = absolutePathForPhotoImage(photo);
|
|
const url = absolutePathForPhoto({ photo, album });
|
|
|
|
return {
|
|
title,
|
|
description: descriptionHtml,
|
|
openGraph: {
|
|
title,
|
|
images,
|
|
description,
|
|
url,
|
|
},
|
|
twitter: {
|
|
title,
|
|
description,
|
|
images,
|
|
card: 'summary_large_image',
|
|
},
|
|
};
|
|
}
|
|
|
|
export default async function PhotoAlbumPage({
|
|
params,
|
|
}: PhotoTagProps) {
|
|
const { photoId, album: albumFromParams } = await params;
|
|
|
|
const albumSlug = decodeURIComponent(albumFromParams);
|
|
|
|
const album = await getAlbumFromSlug(albumSlug);
|
|
|
|
if (!album) { redirect(PATH_ROOT); }
|
|
|
|
const { photo, photos, photosGrid, indexNumber } =
|
|
await getPhotosNearIdCachedCached(photoId, album);
|
|
|
|
if (!photo) { redirect(PATH_ROOT); }
|
|
|
|
const { count, dateRange } = await getPhotosMetaCached({ album });
|
|
|
|
return (
|
|
<PhotoDetailPage {...{
|
|
photo,
|
|
photos,
|
|
photosGrid,
|
|
album,
|
|
indexNumber,
|
|
count,
|
|
dateRange,
|
|
}} />
|
|
);
|
|
}
|