2026-06-22 14:43:46 +08:00

73 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Metadata } from 'next';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { publicApi } from '@/lib/services';
import { formatDate, resolveUploadUrl } from '@/lib/utils';
import { ContentView } from '@/components/front/ContentView';
export const revalidate = 60;
interface PageProps {
params: { id: string };
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
try {
const n = await publicApi.getNewsDetail(Number(params.id));
return { title: n.title, description: n.intro ?? undefined };
} catch {
return { title: '新闻详情' };
}
}
export default async function NewsDetailPage({ params }: PageProps) {
let news;
try {
news = await publicApi.getNewsDetail(Number(params.id));
} catch {
notFound();
}
return (
<article className="container-page py-12">
<nav className="mb-4 text-sm text-gray-500">
<Link href="/news" className="hover:text-brand-600">
</Link>
<span className="mx-2">/</span>
<span>{news.title}</span>
</nav>
<header className="border-b border-gray-100 pb-4">
<h1 className="text-2xl font-bold text-gray-900 sm:text-3xl">
{news.title}
</h1>
<div className="mt-2 flex flex-wrap items-center gap-3 text-xs text-gray-500">
{news.category?.name && (
<span className="rounded bg-brand-50 px-2 py-0.5 text-brand-700">
{news.category.name}
</span>
)}
<span>{formatDate(news.createdAt, 'YYYY-MM-DD HH:mm')}</span>
{news.isTop === 1 && (
<span className="text-red-600"></span>
)}
</div>
</header>
{news.cover && (
<div className="my-6 overflow-hidden rounded-lg">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={resolveUploadUrl(news.cover)}
alt={news.title}
className="max-h-96 w-full object-cover"
/>
</div>
)}
<ContentView content={news.content} className="mt-4 max-w-4xl" />
</article>
);
}