import Link from "next/link"; import { listDocuments, type DocumentMeta } from "@mcpedia/core"; import type { DocSection } from "@mcpedia/core"; export const dynamic = "force-dynamic"; const SECTIONS: { id: DocSection; label: string; icon: string; desc: string }[] = [ { id: "docs", label: "Documentation", icon: "📄", desc: "Setup guides, API references, and protocol specs.", }, { id: "writeups", label: "Writeups", icon: "📝", desc: "Post-mortems, debugging stories, and case studies." }, { id: "research", label: "Research", icon: "🔬", desc: "Deep-dive analysis, architecture notes, and experiments." }, { id: "notes", label: "Notes", icon: "📌", desc: "Quick references, patterns, and gotchas." }, ]; /** * Group documents into a folder tree. Returns nodes where each node is either: * - a folder (has `children`) or * - a leaf doc (has `doc`) * The tree is built from the path segments of each document's `path`. */ interface TreeNode { name: string; slug: string; doc?: DocumentMeta; children?: TreeNode[]; } function buildFolderTree(docs: DocumentMeta[], section: string): TreeNode[] { const root: TreeNode[] = []; const rootMap = new Map(); for (const doc of docs.filter((d) => d.section === section)) { // path is like "docs/websocket/contract.md" → strip section prefix + .md const rel = doc.path.startsWith(`${section}/`) ? doc.path.slice(section.length + 1) : doc.path; const cleanPath = rel.replace(/\.md$/, ""); const parts = cleanPath.split("/"); let currentLevel = root; let currentPath = section; for (let i = 0; i < parts.length; i++) { const part = parts[i]; currentPath = `${currentPath}/${part}`; const isLeaf = i === parts.length - 1; let node = currentLevel.find((n) => n.name === part); if (!node) { node = { name: part === "" ? section : part, slug: currentPath, children: isLeaf ? undefined : [], }; currentLevel.push(node); } if (isLeaf) { node.doc = doc; } else { if (!node.children) node.children = []; currentLevel = node.children; } } } return root; } function renderTree(nodes: TreeNode[], section: DocSection) { return ( ); } export default async function SectionIndexPage({ params, }: { params: Promise<{ section: string }>; }) { const { section } = await params; if (!SECTIONS.some((s) => s.id === section)) { return (

Unknown section

); } const all = await listDocuments(); const sectionDocs = all.filter((d) => d.section === section); const tree = buildFolderTree(all, section as DocSection); const sectionInfo = SECTIONS.find((s) => s.id === section)!; return (
{sectionInfo.icon}

{sectionInfo.label}

{sectionInfo.desc}

Folder structure

{tree.length > 0 ? ( renderTree(tree, section as DocSection) ) : (

No documents found.

)}
{sectionDocs.length > 0 && (

All documents ({sectionDocs.length})

{sectionDocs .sort( (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(), ) .map((d) => ( {d.title} ))}
)}
); }