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 ( ); } export default async function SectionIndexPage({ params, }: { params: Promise<{ section: string }>; }) { const { section } = await params; const sectionInfo = getSectionMeta(section); const allDocs = await listDocuments(); const sectionDocs = allDocs.filter((d) => (d.section || "").toLowerCase() === section.toLowerCase()); const tree = buildFolderTree(allDocs, section); return (
{/* Breadcrumb Navigation */} {/* Hero Card */}
{sectionInfo.icon}

{sectionInfo.label}

Section: {section}

{sectionDocs.length} document{sectionDocs.length !== 1 ? "s" : ""} {sectionDocs.length > 0 && ( Export PDF )} Create Doc

{sectionInfo.desc}

{/* Hierarchical Folder Directory */} {tree.length > 0 && (

Folder & Chapter Structure

{renderTree(tree, section)}
)} {/* Document List */} {sectionDocs.length > 0 ? (

All Documents in {sectionInfo.label}

{[...sectionDocs] .sort( (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(), ) .map((d) => (

{d.title}

{d.tags.length > 0 && (
{d.tags.slice(0, 4).map((t) => ( #{t} ))}
)}
))}
) : (

No documents in this section yet.

)}
); }