import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { Megaphone } from "lucide-react"; import { fetchSitePageBySlug, fetchOverview } from "@/lib/api"; import { getPublicSettingsCached } from "@/lib/serverData"; import { extractToc, estimateReadingMinutes, markdownHeadingToc } from "@/lib/toc"; import MarkdownBody from "@/components/MarkdownBody"; import PostToc from "@/components/PostToc"; import { SiteDocShell, SiteDocIdentity, SiteDocPageNav, SiteDocAnnoNav, SiteDocMasthead, SiteDocBreadcrumb, } from "@/components/site-doc"; interface PageProps { params: Promise<{ slug: string }>; } export async function generateMetadata({ params }: PageProps): Promise { const { slug } = await params; const data = await fetchSitePageBySlug(slug).catch(() => null); if (!data) return { title: "页面不存在" }; const p = data.page; return { title: p.title, description: p.excerpt || p.title, openGraph: { title: p.title, description: p.excerpt || p.title, type: "article", publishedTime: p.created_at, }, }; } export default async function SitePagePublic({ params }: PageProps) { const { slug } = await params; const [data, overview, settings] = await Promise.all([ fetchSitePageBySlug(slug).catch(() => null), fetchOverview().catch(() => null), getPublicSettingsCached(), ]); if (!data) notFound(); const p = data.page; const sidebarPages = overview?.sidebar_pages ?? []; const announcements = overview?.announcements ?? []; const siteLead = settings.site_description?.trim() || undefined; const toc = extractToc(p.content); const headingToc = markdownHeadingToc(toc); const readingMinutes = estimateReadingMinutes(p.content, p.title.length); let headingIndex = 0; const headingRenderer = (Tag: "h2" | "h3") => function Heading({ children }: { children?: React.ReactNode }) { const item = headingToc[headingIndex++]; return ( {children} ); }; const jsonLd = { "@context": "https://schema.org", "@type": "WebPage", name: p.title, description: p.excerpt || undefined, datePublished: p.created_at, dateModified: p.updated_at, }; const left = ( <> ); const right = toc.length > 0 ? ( ) : ( ); return ( <>