qazaq-legacy-foundation-web/src/components/LegalPage.tsx

60 lines
2.4 KiB
TypeScript

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 { Tbc } from '@/components/Tbc'
import { getDict, isLocale, locales } from '@/i18n'
import { loadLegal } from '@/lib/content'
import { buildLegalModel, 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 m = buildLegalModel(await loadLegal(locale), kind, t)
const fmt = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'long', year: 'numeric' })
return (
<>
<Header t={t} locale={locale} showProjects={false} showNews={false} path={`/${kind}`} />
<main className="mx-auto max-w-3xl px-5 pb-24 pt-40 sm:px-8">
<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 />
{m.tbc ? (
<p className="mt-10"><Tbc label={t.tbc} note={t.legal.missing} /></p>
) : (
<div className="mt-10 space-y-5 text-lg leading-relaxed">
{m.paragraphs.map((p, i) => (
<p key={i} className="whitespace-pre-line">{p}</p>
))}
</div>
)}
</main>
<Footer t={t} locale={locale} />
</>
)
}