52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
import type { Metadata } from "next";
|
|
import { notFound } from "next/navigation";
|
|
import { getLettersByRecipient } from "@/lib/letters";
|
|
import { ogForLettersByRecipient } from "@/lib/og";
|
|
import { FilterYearBrowser } from "../../filter-year-browser";
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ name: string }>;
|
|
}): Promise<Metadata> {
|
|
const { name: encodedName } = await params;
|
|
const name = decodeURIComponent(encodedName);
|
|
const letters = await getLettersByRecipient(name);
|
|
if (letters.length === 0) return {};
|
|
return ogForLettersByRecipient(name, letters.length);
|
|
}
|
|
|
|
export default async function LettersByRecipientPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ name: string }>;
|
|
}) {
|
|
const { name: encodedName } = await params;
|
|
const name = decodeURIComponent(encodedName);
|
|
|
|
const letters = await getLettersByRecipient(name);
|
|
if (letters.length === 0) notFound();
|
|
|
|
const serialized = letters.map((l) => ({
|
|
slug: l.slug,
|
|
recipientDisplay: l.recipientDisplay,
|
|
date: l.date,
|
|
year: l.year,
|
|
month: l.month,
|
|
location: l.location,
|
|
}));
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<FilterYearBrowser
|
|
letters={serialized}
|
|
filterName={name}
|
|
filterType="recipient"
|
|
totalCount={letters.length}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|