export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getLetter, getAdjacentLetters } from "@/lib/letters"; import { ogForLetter, extractQuoteFromHl, buildOgMeta } from "@/lib/og"; import { PageHeader } from "@/components/layout/page-header"; import { Card, CardContent } from "@/components/ui/card"; import { buttonVariants } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { JsonLd } from "@/components/seo/json-ld"; import { articleJsonLd } from "@/lib/jsonld"; export async function generateMetadata({ params, searchParams, }: { params: Promise<{ slug: string }>; searchParams: Promise>; }): Promise { const { slug } = await params; const sp = await searchParams; const letter = await getLetter(slug); if (!letter) return {}; const meta = [letter.date, letter.location].filter(Boolean).join(" · "); const hlQuote = extractQuoteFromHl(sp, letter.paragraphs); if (hlQuote) { return buildOgMeta({ title: `Letter to ${letter.recipientDisplay}`, detail: meta || undefined, quote: hlQuote, }); } return ogForLetter(letter.recipientDisplay, meta || undefined); } export default async function LetterPage({ params, }: { params: Promise<{ slug: string }>; }) { const { slug } = await params; const letter = await getLetter(slug); if (!letter) notFound(); const { prev, next } = await getAdjacentLetters(slug, letter.year); const backHref = letter.year ? `/letters/year/${letter.year}` : "/letters"; const backLabel = letter.year ? `Letters from ${letter.year}` : "Letters"; return (
← {backLabel}

Letter to {letter.recipientDisplay}

{letter.date} {letter.location ? ` · ${letter.location}` : ""}

{/* Top nav */} {/* Letter content */}
{letter.paragraphs.map((paragraph, i) => (
))}
{/* Bottom nav */}
); } function LetterNav({ prev, next, }: { prev: { slug: string; recipientDisplay: string } | null; next: { slug: string; recipientDisplay: string } | null; }) { return (
{prev ? ( {prev.recipientDisplay} Previous ) : (
)} {next ? ( {next.recipientDisplay} Next ) : (
)}
); }