refactor: centralize section config — remove all hardcoded section lists
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:
asepharyana
2026-08-21 10:29:35 +07:00
parent 26a900a030
commit 251a6e9b4d
10 changed files with 202 additions and 203 deletions
+8 -12
View File
@@ -35,7 +35,6 @@ export const CONTENT_ROOT =
process.env.CONTENT_ROOT ?? resolve(REPO_ROOT, "content");
export const DATABASE_URL = process.env.DATABASE_URL ?? "";
export const EMBED_BASE_URL = process.env.EMBED_BASE_URL ?? "";
export const EMBED_API_KEY = process.env.EMBED_API_KEY ?? "";
export const EMBED_MODEL = process.env.EMBED_MODEL ?? "";
@@ -43,20 +42,17 @@ export const EMBED_MODEL = process.env.EMBED_MODEL ?? "";
// Phase 3: Redis + BullMQ (shared imrnes Redis, no auth by default).
export const REDIS_URL = process.env.REDIS_URL ?? "redis://100.121.180.82:6379";
export const REDIS_PASSWORD = process.env.REDIS_PASSWORD ?? "";
// BullMQ key prefix to namespace jobs on the shared Redis instance.
export const QUEUE_PREFIX = process.env.QUEUE_PREFIX ?? "mcpedia";
// Phase 4: git-sync webhook shared secret. The API /hooks/* endpoints require
// this header (x-webhook-secret) to match, so an open port can't trigger reindex.
// Phase 4: git-sync webhook shared secret.
export const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
// Phase 11: Admin password for web-based CRUD (create/update/delete documents).
// Used by the Web UI login flow. MCP/API writes still use WEBHOOK_SECRET.
// Phase 11: Admin password for web-based CRUD.
export const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD ?? "";
// NOTE: we deliberately do NOT throw here if DATABASE_URL is empty. Throwing at
// import time breaks `next build` (SSG data collection imports config before
// any .env is present) and any runtime-injected env (containers/systemd set env
// at process start, after module load). The DB driver (postgres.js) connects
// lazily on first query, so a missing DATABASE_URL surfaces as a clear connect
// error at runtime — not a cryptic build failure.
// Phase 14: Section registry — re-exported from a Node-free module so client
// components can safely import SECTIONS without pulling in node:fs.
export { SECTIONS, SECTIONS_BY_ID, SECTION_IDS, type SectionConfig } from "./sections";
// NOTE: we deliberately do NOT throw here if DATABASE_URL is empty.
// Throwing at import time breaks `next build` SSG and any runtime-injected env.
+44
View File
@@ -0,0 +1,44 @@
/**
* Section registry — defines all content sections for the UI.
* This file is intentionally free of Node.js built-in imports (no fs/path)
* so it can be safely imported by client components.
*
* Adding a new section is as simple as adding an entry here + creating a
* `content/<id>/` directory with markdown files. No UI code changes needed.
*/
export interface SectionConfig {
id: string;
label: string;
icon: string;
desc: string;
}
export const SECTIONS: SectionConfig[] = [
{
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.",
},
];
export const SECTIONS_BY_ID = new Map(SECTIONS.map((s) => [s.id, s]));
export const SECTION_IDS = SECTIONS.map((s) => s.id);