import Link from "next/link"; import { notFound } from "next/navigation"; import { cookies } from "next/headers"; import { getDocument, getRelated, listRevisions } from "@mcpedia/core"; import { WEBHOOK_SECRET } from "@mcpedia/config"; import Markdown from "@/components/Markdown"; import DocForm from "@/components/DocForm"; import TOC from "@/components/TOC"; // Render at request time. The content lives in Postgres (populated by the // indexer/worker), which is not available at build time (CI has no DB), so we // opt out of static generation. At this corpus scale request-time rendering is // instant. export const dynamic = "force-dynamic"; interface DocPageProps { params: Promise<{ section: string; slug: string[] }>; searchParams: Promise<{ edit?: string }>; } export default async function DocPage({ params, searchParams }: DocPageProps) { const { section, slug } = await params; const { edit } = await searchParams; const fullSlug = `${section}/${slug.join("/")}`; const doc = await getDocument(fullSlug); if (!doc) notFound(); // Check auth for edit mode. const cookieStore = await cookies(); const canEdit = cookieStore.get("mcpedia_admin")?.value != null; // If ?edit=1 and authenticated → show the edit form. if (edit === "1" && canEdit) { return (

Edit: {doc.title}

); } const related = await getRelated(fullSlug, 5); const revisions = await listRevisions(fullSlug, 10); return (
← Back

{doc.title}

{doc.tags.map((t) => `#${t}`).join(" ")} · {doc.author || "unknown"}
{canEdit && ( Edit )}
{related.length > 0 && ( )} {revisions.length > 0 && ( )}
); }