* 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
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
|
|
import { getUniqueYears } from '@/photo/db/query';
|
|
import { generateMetaForYear } from '@/years/meta';
|
|
import YearOverview from '@/years/YearOverview';
|
|
import { getPhotosYearDataCached } from '@/years/data';
|
|
import { Metadata } from 'next/types';
|
|
import { cache } from 'react';
|
|
import { PATH_ROOT } from '@/app/paths';
|
|
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,
|
|
}} />
|
|
);
|
|
}
|