import Link from "next/link"; import { listDocuments } from "@mcpedia/core"; import { getSectionMeta } from "@mcpedia/config"; import { Folder, FileText, FileDown, Plus, Clock, } from "lucide-react"; export const dynamic = "force-dynamic"; interface DocMeta { slug: string; title: string; section: string; tags: string[]; updatedAt: string; path: string; } interface TreeNode { name: string; slug: string; doc?: DocMeta; children: TreeNode[]; docCount: number; } function buildFolderTree(docs: DocMeta[], section: string): TreeNode[] { const root: TreeNode[] = []; for (const doc of docs.filter((d) => (d.section || "").toLowerCase() === section.toLowerCase())) { const rel = doc.slug.startsWith(`${section}/`) ? doc.slug.slice(section.length + 1) : doc.slug; const parts = rel.split("/"); let current = root; let currentPath = section; for (let i = 0; i < parts.length; i++) { const part = parts[i]; const isLeaf = i === parts.length - 1; currentPath = `${currentPath}/${part}`; let node = current.find((n) => n.name === part); if (!node) { node = { name: part, slug: currentPath, children: [], docCount: 0, }; current.push(node); } if (isLeaf) { node.doc = doc; node.docCount = 1; } current = node.children; } } function countDocs(node: TreeNode): number { if (node.doc) return 1; return node.children.reduce((sum, child) => sum + countDocs(child), 0); } for (const node of root) { node.docCount = countDocs(node); } return root; } function renderTree(nodes: TreeNode[], pathname: string) { return (
Section: {section}
{sectionInfo.desc}
No documents in this section yet.