* 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
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
|
|
import { getUniqueYears } from '@/photo/query';
|
|
import { generateMetaForYear } from '@/year/meta';
|
|
import YearOverview from '@/year/YearOverview';
|
|
import { getPhotosYearDataCached } from '@/year/data';
|
|
import { Metadata } from 'next/types';
|
|
import { cache } from 'react';
|
|
import { PATH_ROOT } from '@/app/path';
|
|
import { redirect } from 'next/navigation';
|
|
import { staticallyGenerateCategoryIfConfigured } from '@/app/static';
|
|
import { getAppText } from '@/i18n/state/server';
|
|
|
|
const getPhotosYearDataCachedCached = cache((year: string) =>
|
|
getPhotosYearDataCached({ year, limit: INFINITE_SCROLL_GRID_INITIAL }));
|
|
|
|
export const generateStaticParams = staticallyGenerateCategoryIfConfigured(
|
|
'years',
|
|
'page',
|
|
getUniqueYears,
|
|
years => years.map(({ year }) => ({ year })),
|
|
);
|
|
|
|
interface YearProps {
|
|
params: Promise<{ year: string }>
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: YearProps): Promise<Metadata> {
|
|
const { year } = await params;
|
|
|
|
const [
|
|
photos,
|
|
{ count, dateRange },
|
|
] = await getPhotosYearDataCachedCached(year);
|
|
|
|
if (photos.length === 0) { return {}; }
|
|
|
|
const appText = await getAppText();
|
|
|
|
const {
|
|
url,
|
|
title,
|
|
description,
|
|
images,
|
|
} = generateMetaForYear(year, photos, appText, count, dateRange);
|
|
|
|
return {
|
|
title,
|
|
openGraph: {
|
|
title,
|
|
description,
|
|
images,
|
|
url,
|
|
},
|
|
twitter: {
|
|
images,
|
|
description,
|
|
card: 'summary_large_image',
|
|
},
|
|
description,
|
|
};
|
|
}
|
|
|
|
export default async function YearPage({
|
|
params,
|
|
}: YearProps) {
|
|
const { year } = await params;
|
|
|
|
const [
|
|
photos,
|
|
{ count, dateRange },
|
|
] = await getPhotosYearDataCachedCached(year);
|
|
|
|
if (photos.length === 0) { redirect(PATH_ROOT); }
|
|
|
|
return (
|
|
<YearOverview {...{
|
|
year,
|
|
photos,
|
|
count,
|
|
dateRange,
|
|
}} />
|
|
);
|
|
}
|