import type { Metadata } from "next"; import Link from "next/link"; import { Megaphone } from "lucide-react"; import { fetchAnnouncementsPage, type Announcement } from "@/lib/api"; import { formatDate } from "@/lib/format"; import Pagination from "@/components/Pagination"; export const metadata: Metadata = { title: "站点公告", description: "站点公告与通知列表", }; interface PageProps { searchParams: Promise<{ page?: string }>; } /** 粗略去掉 Markdown,取摘要 */ function plainSummary(md: string, max = 120): string { const text = md .replace(/```[\s\S]*?```/g, " ") .replace(/!\[[^\]]*\]\([^)]+\)/g, " ") .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") .replace(/[#>*_`~\-|=]/g, "") .replace(/\s+/g, " ") .trim(); return text.length > max ? `${text.slice(0, max)}…` : text; } function AnnouncementCard({ a }: { a: Announcement }) { const summary = plainSummary(a.content); return (
{summary}
) : null} ); } export default async function AnnouncementsListPage({ searchParams }: PageProps) { const sp = await searchParams; const page = Math.max(1, parseInt(sp.page || "1", 10) || 1); const size = 20; let announcements: Announcement[] = []; let total = 0; let error = ""; try { const res = await fetchAnnouncementsPage(page, size); announcements = res.announcements ?? []; total = res.total ?? 0; } catch (e) { error = e instanceof Error ? e.message : "加载公告失败"; } return (站点通知与运营公告
{error}
) : announcements.length === 0 ? (暂无公告
有新消息时会显示在这里