31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import Link from 'next/link'
|
|
import { notFound } from 'next/navigation'
|
|
import { getDict, isLocale, locales } from '@/i18n'
|
|
import { loadNews } from '@/lib/content'
|
|
import { visibleNews } from '@/lib/news-model'
|
|
import { SectionPage } from '@/components/SectionPage'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
|
|
const { locale } = await params
|
|
if (!isLocale(locale)) notFound()
|
|
const t = getDict(locale)
|
|
return { title: `${t.news.title} — ${t.siteName}`, description: t.metaDescription, alternates: { languages: Object.fromEntries(locales.map(l => [l, `/${l}/news`])) } }
|
|
}
|
|
export default async function Page({ params }: { params: Promise<{ locale: string }> }) {
|
|
const { locale } = await params
|
|
if (!isLocale(locale)) notFound()
|
|
const t = getDict(locale)
|
|
const news = visibleNews(await loadNews(locale))
|
|
if (!news.length) notFound()
|
|
const fmt = new Intl.DateTimeFormat(locale, { dateStyle: 'long' })
|
|
return <SectionPage t={t} locale={locale} path="/news" title={t.news.title} showNews>
|
|
<ul className="divide-y divide-line">{news.map(n => <li key={n.id} className="py-7">
|
|
<time dateTime={n.date}>{fmt.format(new Date(n.date))}</time>
|
|
<h2 className="mt-3 font-serif text-2xl"><Link href={`/${locale}/news/${n.id}`} className="underline underline-offset-4">{n.title}</Link></h2>
|
|
{n.summary && <p className="mt-4">{n.summary}</p>}
|
|
</li>)}</ul>
|
|
</SectionPage>
|
|
}
|