2026-08-21 08:37:41 +07:00
|
|
|
import { listDocuments, extractFoldersForSection } from "@mcpedia/core";
|
2026-08-20 13:08:27 +07:00
|
|
|
import { cookies } from "next/headers";
|
2026-08-21 08:37:41 +07:00
|
|
|
import { redirect } from "next/navigation";
|
2026-08-20 13:08:27 +07:00
|
|
|
import DocForm from "@/components/DocForm";
|
2026-08-21 08:37:41 +07:00
|
|
|
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
|
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
2026-08-20 13:08:27 +07:00
|
|
|
|
2026-08-20 16:57:30 +07:00
|
|
|
export default async function CreatePage() {
|
2026-08-20 13:08:27 +07:00
|
|
|
const cookieStore = await cookies();
|
|
|
|
|
const canEdit = cookieStore.get("mcpedia_admin")?.value != null;
|
2026-08-21 08:37:41 +07:00
|
|
|
if (!canEdit) redirect("/login");
|
|
|
|
|
|
|
|
|
|
const allDocs = await listDocuments();
|
|
|
|
|
|
|
|
|
|
// Build folder suggestions per section using the shared helper from core
|
|
|
|
|
const sections = ["docs", "writeups", "research", "notes"];
|
|
|
|
|
const docPaths = allDocs.map((d) => d.path);
|
|
|
|
|
const foldersBySection: Record<string, string[]> = {};
|
|
|
|
|
for (const sec of sections) {
|
|
|
|
|
foldersBySection[sec] = extractFoldersForSection(docPaths, sec);
|
2026-08-20 13:08:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-08-20 16:57:30 +07:00
|
|
|
<div>
|
2026-08-21 08:37:41 +07:00
|
|
|
<h1 className="text-3xl font-medium text-[#f7f8f8] mb-6">Create Document</h1>
|
|
|
|
|
<DocForm
|
|
|
|
|
mode="create"
|
|
|
|
|
secret={WEBHOOK_SECRET}
|
|
|
|
|
existingFolders={foldersBySection}
|
|
|
|
|
/>
|
2026-08-20 13:08:27 +07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|