refactor: centralize section config — remove all hardcoded section lists
CI / typecheck + build (turbo) (push) Canceled after 0s
CI / typecheck + build (turbo) (push) Canceled after 0s
- New packages/config/src/sections.ts: SECTIONS, SECTIONS_BY_ID, SECTION_IDS (no Node.js built-in imports — safe for client components) - New package entrypoint: @mcpedia/config/sections (exports only sections.ts) - Client components import from @mcpedia/config/sections (no node:fs in bundle) - Server components import from @mcpedia/config (has env/fs, server-only) - Removed hardcoded SECTIONS/SECTION_LABEL/SECTION_ICON from: - [section]/page.tsx (was inline array) - [section]/[...slug]/page.tsx (was hardcoded Record maps) - Sidebar.tsx (was inline array) - layout.tsx (was inline array) - page.tsx (was inline array) - create/page.tsx (was inline array via SECTIONS import) - Added @mcpedia/config/sections entrypoint to package.json exports
This commit is contained in:
@@ -1,33 +1,31 @@
|
||||
import { listDocuments, extractFoldersForSection } from "@mcpedia/core";
|
||||
import { SECTIONS } from "@mcpedia/config/sections";
|
||||
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import DocForm from "@/components/DocForm";
|
||||
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function CreatePage() {
|
||||
const cookieStore = await cookies();
|
||||
const canEdit = cookieStore.get("mcpedia_admin")?.value != null;
|
||||
if (!canEdit) redirect("/login");
|
||||
const isAdmin = cookieStore.get("mcpedia_admin")?.value != null;
|
||||
if (!isAdmin) redirect("/login");
|
||||
|
||||
const allDocs = await listDocuments();
|
||||
const docPaths = allDocs.map((d) => d.path);
|
||||
|
||||
// Build folder suggestions per section using the shared core helper
|
||||
const sections = ["docs", "writeups", "research", "notes"];
|
||||
const foldersBySection: Record<string, string[]> = {};
|
||||
for (const sec of sections) {
|
||||
foldersBySection[sec] = extractFoldersForSection(docPaths, sec);
|
||||
}
|
||||
const all = await listDocuments();
|
||||
const docPaths = all.map((d) => d.path);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-3xl font-medium text-[#f7f8f8] mb-6">Create Document</h1>
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<span className="text-2xl">✏️</span>
|
||||
<h1 className="text-2xl font-medium text-[#f7f8f8]">Create Document</h1>
|
||||
</div>
|
||||
|
||||
<DocForm
|
||||
mode="create"
|
||||
secret={WEBHOOK_SECRET}
|
||||
existingFolders={foldersBySection}
|
||||
existingFolders={Object.fromEntries(
|
||||
SECTIONS.map((s) => [s.id, extractFoldersForSection(docPaths, s.id)])
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user