57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import { LegalText } from '@/components/LegalText'
|
|
import type { Metadata } from 'next'
|
|
import Link from 'next/link'
|
|
import { notFound } from 'next/navigation'
|
|
import { Footer } from '@/components/Footer'
|
|
import { Header } from '@/components/Header'
|
|
import { getDict, isLocale, locales } from '@/i18n'
|
|
import { loadContent, loadLegal } from '@/lib/content'
|
|
import { buildLegalModel, isLegalPublished, type LegalKind } from '@/lib/legal-model'
|
|
|
|
type Props = { params: Promise<{ locale: string }> }
|
|
|
|
export const legalMetadata = (kind: LegalKind) =>
|
|
async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
const { locale } = await params
|
|
if (!isLocale(locale)) return {}
|
|
const t = getDict(locale)
|
|
const title = `${t.legal[kind].title} — ${t.siteName}`
|
|
return {
|
|
title,
|
|
description: t.legal[kind].description,
|
|
alternates: { languages: Object.fromEntries(locales.map((l) => [l, `/${l}/${kind}`])) },
|
|
openGraph: { title, description: t.legal[kind].description, type: 'website', locale },
|
|
}
|
|
}
|
|
|
|
export async function LegalPage({ params, kind }: Props & { kind: LegalKind }) {
|
|
const { locale } = await params
|
|
if (!isLocale(locale)) notFound()
|
|
const t = getDict(locale)
|
|
const legal = await loadLegal(locale)
|
|
if (!isLegalPublished(legal?.[kind])) notFound()
|
|
const { news } = await loadContent(locale)
|
|
const m = buildLegalModel(legal, kind, t)
|
|
const fmt = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'long', year: 'numeric' })
|
|
|
|
return (
|
|
<>
|
|
<Header t={t} locale={locale} showProjects showNews={news.length > 0} path={`/${kind}`} />
|
|
<main className="mx-auto max-w-3xl px-5 pb-24 pt-64 sm:px-8 sm:pt-56 md:pt-44">
|
|
<Link href={`/${locale}`} className="text-sm text-muted hover:text-burgundy">← {t.legal.back}</Link>
|
|
<h1 className="mt-6 font-serif text-4xl leading-tight text-burgundy sm:text-5xl">{m.title}</h1>
|
|
{m.updated && (
|
|
<p className="mt-4 text-sm text-muted">
|
|
{t.legal.updated} <time dateTime={m.updated}>{fmt.format(new Date(m.updated))}</time>
|
|
</p>
|
|
)}
|
|
<div className="mt-10 h-px w-24 bg-burgundy" aria-hidden />
|
|
<div className="mt-10 space-y-5 text-lg leading-relaxed">
|
|
<LegalText paragraphs={m.paragraphs} />
|
|
</div>
|
|
</main>
|
|
<Footer t={t} locale={locale} legal={await loadLegal(locale)} />
|
|
</>
|
|
)
|
|
}
|