qazaq-legacy-foundation-web/src/app/(site)/[locale]/news/[id]/page.tsx
Peppa 1a58c2a4d9
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 1с
peppa/build build: success за 41с
ci / checks (pull_request) Successful in 1m22s
deploy / deploy (pull_request) Successful in 17s
QLFW-6: панель управления: проекты, фото, контакты и текст «О фонде»
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 23:33:54 +05:00

40 lines
2.2 KiB
TypeScript

import Link from 'next/link'
import { notFound } from 'next/navigation'
import { getDict, isLocale, locales } from '@/i18n'
import { loadNews, loadLegal } from '@/lib/content'
import { newsImage, visibleNews } from '@/lib/news-model'
import { SectionPage } from '@/components/SectionPage'
export const dynamic = 'force-dynamic'
import { safeWebUrl } from '@/lib/news-model'
import Image from 'next/image'
import { cache } from 'react'
const findNews = cache(async (locale: 'ru' | 'kk' | 'en', id: string) => visibleNews(await loadNews(locale)).find(n => String(n.id) === id))
export async function generateMetadata({ params }: { params: Promise<{ locale: string; id: string }> }) {
const { locale, id } = await params
if (!isLocale(locale)) notFound()
const n = await findNews(locale, id)
if (!n) notFound()
return { title: `${n.title} — ${getDict(locale).siteName}`, description: n.summary || n.title, alternates: { languages: Object.fromEntries(locales.map(l => [l, `/${l}/news/${id}`])) } }
}
export default async function Page({ params }: { params: Promise<{ locale: string; id: string }> }) {
const { locale, id } = await params
if (!isLocale(locale)) notFound()
const t = getDict(locale)
const n = await findNews(locale, id)
if (!n) notFound()
const image = newsImage(n)
const source = safeWebUrl(n.sourceUrl)
return <SectionPage legal={await loadLegal(locale)} t={t} locale={locale} path={`/news/${id}`} title={n.title} showNews>
<article className="max-w-3xl">
<time dateTime={n.date}>{new Intl.DateTimeFormat(locale, { dateStyle: 'long' }).format(new Date(n.date))}</time>
{n.place && <p className="mt-3">{n.place}</p>}
{image && <Image unoptimized width={1200} height={800} src={image} alt={n.title} loading="lazy" className="mt-8 h-auto max-w-full" />}
{(n.body || n.summary || t.tbc).split(/\n\s*\n/).map((text, index) => <p key={index} className="mt-6 whitespace-pre-line leading-relaxed">{text}</p>)}
{source && <p className="mt-8"><a href={source} rel="noopener noreferrer" className="underline underline-offset-4">{t.sections.source}</a></p>}
<Link href={`/${locale}/news`} className="mt-10 inline-flex min-h-11 items-center underline underline-offset-4">{t.news.title}</Link>
</article>
</SectionPage>
}