import type { Metadata } from "next"; import Link from "next/link"; import { cookies } from "next/headers"; import { notFound } from "next/navigation"; import { ChevronRight, Megaphone } from "lucide-react"; import { fetchAnnouncementDetail } from "@/lib/api"; import { authCookieHeader } from "@/lib/cookies"; import { formatDate } from "@/lib/format"; import { getMeCached } from "@/lib/serverData"; import MarkdownBody from "@/components/MarkdownBody"; interface PageProps { params: Promise<{ id: string }>; } export async function generateMetadata({ params }: PageProps): Promise { const { id } = await params; const data = await fetchAnnouncementDetail(id).catch(() => null); if (!data) return { title: "公告不存在" }; return { title: data.announcement.title, description: `站点公告 · ${data.announcement.tag}`, openGraph: { title: data.announcement.title, description: `站点公告 · ${data.announcement.tag}`, type: "article", publishedTime: data.announcement.created_at, }, }; } export default async function AnnouncementPage({ params }: PageProps) { const { id } = await params; const cookie = authCookieHeader(await cookies()); const [data, me] = await Promise.all([ fetchAnnouncementDetail(id, cookie || undefined).catch(() => null), getMeCached(cookie || undefined), ]); if (!data) notFound(); const a = data.announcement; const loginHref = `/login?redirect=${encodeURIComponent(`/announcement/${id}`)}`; const jsonLd = { "@context": "https://schema.org", "@type": "Article", headline: a.title, datePublished: a.created_at, dateModified: a.updated_at, articleSection: "站点公告", keywords: a.tag, }; return (