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 (content in Postgres, not available at build time). 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(); const cookieStore = await cookies(); const canEdit = cookieStore.get("mcpedia_admin")?.value != null; // Edit mode: inline form if (edit === "1" && canEdit) { return (
← Back to {doc.title}

Edit: {doc.title}

); } const related = await getRelated(fullSlug, 5); const revisions = await listRevisions(fullSlug, 10); return (
MCPedia / Docs {canEdit && ( <> / Edit )}

{doc.title}

{doc.author || "unknown"} • {new Date(doc.updatedAt).toLocaleDateString()} {doc.tags.map((t) => ( #{t} ))}
{related.length > 0 && ( )} {revisions.length > 0 && ( )}
); }