Files
spsays-training/app/letters/location/[name]/page.tsx
T
2026-05-06 01:19:06 +05:30

52 lines
1.3 KiB
TypeScript

export const dynamic = "force-dynamic";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { getLettersByLocation } from "@/lib/letters";
import { ogForLettersByLocation } 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 getLettersByLocation(name);
if (letters.length === 0) return {};
return ogForLettersByLocation(name, letters.length);
}
export default async function LettersByLocationPage({
params,
}: {
params: Promise<{ name: string }>;
}) {
const { name: encodedName } = await params;
const name = decodeURIComponent(encodedName);
const letters = await getLettersByLocation(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="location"
totalCount={letters.length}
/>
</div>
);
}