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:
@@ -7,6 +7,7 @@ import Markdown from "@/components/Markdown";
|
|||||||
import DocForm from "@/components/DocForm";
|
import DocForm from "@/components/DocForm";
|
||||||
import TOC from "@/components/TOC";
|
import TOC from "@/components/TOC";
|
||||||
import { classifyPath, extractFoldersForSection } from "@mcpedia/core";
|
import { classifyPath, extractFoldersForSection } from "@mcpedia/core";
|
||||||
|
import { SECTIONS_BY_ID } from "@mcpedia/config/sections";
|
||||||
import type { DocumentMeta } from "@mcpedia/core";
|
import type { DocumentMeta } from "@mcpedia/core";
|
||||||
|
|
||||||
// Render at request time (content in Postgres, not available at build time).
|
// Render at request time (content in Postgres, not available at build time).
|
||||||
@@ -17,19 +18,22 @@ interface DocPageProps {
|
|||||||
searchParams: Promise<{ edit?: string }>;
|
searchParams: Promise<{ edit?: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SECTION_LABEL: Record<string, string> = {
|
/**
|
||||||
docs: "Documentation",
|
* Get section label and icon from the centralized config.
|
||||||
writeups: "Writeup",
|
*/
|
||||||
research: "Research",
|
function getSectionInfo(section: string) {
|
||||||
notes: "Note",
|
const info = SECTIONS_BY_ID.get(section);
|
||||||
};
|
if (!info) {
|
||||||
|
return {
|
||||||
const SECTION_ICON: Record<string, string> = {
|
label: section.charAt(0).toUpperCase() + section.slice(1),
|
||||||
docs: "📄",
|
icon: "📄",
|
||||||
writeups: "📝",
|
};
|
||||||
research: "🔬",
|
}
|
||||||
notes: "📌",
|
return {
|
||||||
};
|
label: info.label,
|
||||||
|
icon: info.icon,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render any extra/custom frontmatter fields as labeled badges.
|
* Render any extra/custom frontmatter fields as labeled badges.
|
||||||
@@ -167,10 +171,7 @@ function FolderIndexPage({
|
|||||||
|
|
||||||
const folders = [...immediateFolders.entries()].sort(([a], [b]) => a.localeCompare(b));
|
const folders = [...immediateFolders.entries()].sort(([a], [b]) => a.localeCompare(b));
|
||||||
|
|
||||||
const sectionInfo = {
|
const sectionInfo = getSectionInfo(section);
|
||||||
icon: SECTION_ICON[section] || "📁",
|
|
||||||
label: SECTION_LABEL[section] || section,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -366,6 +367,8 @@ export default async function DocPage({ params, searchParams }: DocPageProps) {
|
|||||||
const related = await getRelated(fullSlug, 5);
|
const related = await getRelated(fullSlug, 5);
|
||||||
const revisions = await listRevisions(fullSlug, 10);
|
const revisions = await listRevisions(fullSlug, 10);
|
||||||
|
|
||||||
|
const sectionInfo = getSectionInfo(doc.section);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article>
|
<article>
|
||||||
{/* Breadcrumb — dynamic based on the doc's actual path */}
|
{/* Breadcrumb — dynamic based on the doc's actual path */}
|
||||||
@@ -380,7 +383,7 @@ export default async function DocPage({ params, searchParams }: DocPageProps) {
|
|||||||
const crumbPath = doc.slug.split("/").slice(0, i + 1).join("/");
|
const crumbPath = doc.slug.split("/").slice(0, i + 1).join("/");
|
||||||
const isLast = i === doc.slug.split("/").length - 1;
|
const isLast = i === doc.slug.split("/").length - 1;
|
||||||
const label = i === 0
|
const label = i === 0
|
||||||
? SECTION_LABEL[part] || part
|
? sectionInfo.label
|
||||||
: part
|
: part
|
||||||
.split(/[-_]/)
|
.split(/[-_]/)
|
||||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||||
@@ -408,12 +411,12 @@ export default async function DocPage({ params, searchParams }: DocPageProps) {
|
|||||||
<div className="bg-[#0f1011] border border-[#1f2022] rounded-lg p-6 mb-8">
|
<div className="bg-[#0f1011] border border-[#1f2022] rounded-lg p-6 mb-8">
|
||||||
<div className="flex items-start gap-3 mb-4">
|
<div className="flex items-start gap-3 mb-4">
|
||||||
<span className="text-2xl">
|
<span className="text-2xl">
|
||||||
{SECTION_ICON[doc.section] || "📄"}
|
{sectionInfo.icon}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<span className="text-xs font-medium text-[#7170ff] uppercase">
|
<span className="text-xs font-medium text-[#7170ff] uppercase">
|
||||||
{SECTION_LABEL[doc.section] || doc.section}
|
{sectionInfo.label}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-[#62666d]">·</span>
|
<span className="text-xs text-[#62666d]">·</span>
|
||||||
<span className="text-xs text-[#62666d]">
|
<span className="text-xs text-[#62666d]">
|
||||||
@@ -475,38 +478,41 @@ export default async function DocPage({ params, searchParams }: DocPageProps) {
|
|||||||
Related Documents
|
Related Documents
|
||||||
</h2>
|
</h2>
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
{related.map((r) => (
|
{related.map((r) => {
|
||||||
<Link
|
const rInfo = getSectionInfo(r.section);
|
||||||
key={r.slug}
|
return (
|
||||||
href={`/${r.slug}`}
|
<Link
|
||||||
className="group block bg-[#0f1011] border border-[#1f2022] rounded-lg p-4 hover:border-[#5e6ad2]/40 hover:bg-[#131415] transition-all duration-200"
|
key={r.slug}
|
||||||
>
|
href={`/${r.slug}`}
|
||||||
<div className="flex items-start gap-2 mb-2">
|
className="group block bg-[#0f1011] border border-[#1f2022] rounded-lg p-4 hover:border-[#5e6ad2]/40 hover:bg-[#131415] transition-all duration-200"
|
||||||
<span className="text-xl">
|
>
|
||||||
{SECTION_ICON[r.section] || "📄"}
|
<div className="flex items-start gap-2 mb-2">
|
||||||
</span>
|
<span className="text-xl">
|
||||||
<time className="text-xs text-[#62666d]">
|
{rInfo.icon}
|
||||||
{new Date(r.updatedAt).toLocaleDateString(undefined, {
|
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
})}
|
|
||||||
</time>
|
|
||||||
</div>
|
|
||||||
<h3 className="font-medium text-[#f7f8f8] group-hover:text-[#7170ff] transition-colors line-clamp-1 mb-1">
|
|
||||||
{r.title}
|
|
||||||
</h3>
|
|
||||||
<div className="flex flex-wrap gap-1 mt-2">
|
|
||||||
{r.tags.slice(0, 3).map((t) => (
|
|
||||||
<span
|
|
||||||
key={t}
|
|
||||||
className="text-xs px-1.5 py-0.5 bg-[#191a1b] border border-[#23252a] rounded text-[#d0d6e0]"
|
|
||||||
>
|
|
||||||
#{t}
|
|
||||||
</span>
|
</span>
|
||||||
))}
|
<time className="text-xs text-[#62666d]">
|
||||||
</div>
|
{new Date(r.updatedAt).toLocaleDateString(undefined, {
|
||||||
</Link>
|
month: "short",
|
||||||
))}
|
day: "numeric",
|
||||||
|
})}
|
||||||
|
</time>
|
||||||
|
</div>
|
||||||
|
<h3 className="font-medium text-[#f7f8f8] group-hover:text-[#7170ff] transition-colors line-clamp-1 mb-1">
|
||||||
|
{r.title}
|
||||||
|
</h3>
|
||||||
|
<div className="flex flex-wrap gap-1 mt-2">
|
||||||
|
{r.tags.slice(0, 3).map((t) => (
|
||||||
|
<span
|
||||||
|
key={t}
|
||||||
|
className="text-xs px-1.5 py-0.5 bg-[#191a1b] border border-[#23252a] rounded text-[#d0d6e0]"
|
||||||
|
>
|
||||||
|
#{t}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { listDocuments } from "@mcpedia/core";
|
import { listDocuments } from "@mcpedia/core";
|
||||||
|
import { SECTIONS } from "@mcpedia/config/sections";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -12,18 +13,6 @@ interface DocMeta {
|
|||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SECTIONS: { id: string; label: string; icon: string; desc: string }[] = [
|
|
||||||
{
|
|
||||||
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." },
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a hierarchical folder tree from a flat list of documents.
|
* Build a hierarchical folder tree from a flat list of documents.
|
||||||
* Each node is either a folder (has children) or a leaf doc.
|
* Each node is either a folder (has children) or a leaf doc.
|
||||||
@@ -68,8 +57,6 @@ function buildFolderTree(docs: DocMeta[], section: string): TreeNode[] {
|
|||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
node.doc = doc;
|
node.doc = doc;
|
||||||
node.docCount = 1;
|
node.docCount = 1;
|
||||||
} else {
|
|
||||||
// This is a folder — count will be accumulated below
|
|
||||||
}
|
}
|
||||||
current = node.children;
|
current = node.children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
import { SECTIONS } from "@mcpedia/config/sections";
|
||||||
|
|
||||||
interface Doc {
|
interface Doc {
|
||||||
slug: string;
|
slug: string;
|
||||||
@@ -11,13 +12,6 @@ interface Doc {
|
|||||||
tags: string[];
|
tags: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const SECTIONS = [
|
|
||||||
{ id: "docs", label: "Documentation", icon: "📄" },
|
|
||||||
{ id: "writeups", label: "Writeups", icon: "📝" },
|
|
||||||
{ id: "research", label: "Research", icon: "🔬" },
|
|
||||||
{ id: "notes", label: "Notes", icon: "📌" },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a hierarchical folder tree from flat document slugs.
|
* Build a hierarchical folder tree from flat document slugs.
|
||||||
* Each node is either a folder (has children) or a leaf doc.
|
* Each node is either a folder (has children) or a leaf doc.
|
||||||
@@ -132,7 +126,7 @@ function renderTreeNode(
|
|||||||
</Link>
|
</Link>
|
||||||
{node.children.length > 0 && (
|
{node.children.length > 0 && (
|
||||||
<ul className="mt-0.5">
|
<ul className="mt-0.5">
|
||||||
{node.children.map((child) => renderTreeNode(child, 0, pathname))}
|
{node.children.map((child) => renderTreeNode(child, depth + 1, pathname))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,33 +1,31 @@
|
|||||||
import { listDocuments, extractFoldersForSection } from "@mcpedia/core";
|
import { listDocuments, extractFoldersForSection } from "@mcpedia/core";
|
||||||
|
import { SECTIONS } from "@mcpedia/config/sections";
|
||||||
|
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import DocForm from "@/components/DocForm";
|
import DocForm from "@/components/DocForm";
|
||||||
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
|
||||||
|
|
||||||
export default async function CreatePage() {
|
export default async function CreatePage() {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
const canEdit = cookieStore.get("mcpedia_admin")?.value != null;
|
const isAdmin = cookieStore.get("mcpedia_admin")?.value != null;
|
||||||
if (!canEdit) redirect("/login");
|
if (!isAdmin) redirect("/login");
|
||||||
|
|
||||||
const allDocs = await listDocuments();
|
const all = await listDocuments();
|
||||||
const docPaths = allDocs.map((d) => d.path);
|
const docPaths = all.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<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
|
<DocForm
|
||||||
mode="create"
|
mode="create"
|
||||||
secret={WEBHOOK_SECRET}
|
secret={WEBHOOK_SECRET}
|
||||||
existingFolders={foldersBySection}
|
existingFolders={Object.fromEntries(
|
||||||
|
SECTIONS.map((s) => [s.id, extractFoldersForSection(docPaths, s.id)])
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -72,3 +72,17 @@ body {
|
|||||||
.prose tbody tr:nth-child(even) {
|
.prose tbody tr:nth-child(even) {
|
||||||
background: rgba(15, 16, 17, 0.5);
|
background: rgba(15, 16, 17, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Inline code in prose */
|
||||||
|
.prose code {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Blockquote styling */
|
||||||
|
.prose blockquote {
|
||||||
|
border-left: 2px solid var(--color-border);
|
||||||
|
margin: 1.5em 0;
|
||||||
|
padding: 0.25em 1em;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|||||||
+17
-35
@@ -3,6 +3,7 @@ import Link from "next/link";
|
|||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import ThemeToggle from "@/components/ThemeToggle";
|
import ThemeToggle from "@/components/ThemeToggle";
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
|
import { SECTIONS } from "@mcpedia/config/sections";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "MCPedia — Knowledge base for humans and AI agents",
|
title: "MCPedia — Knowledge base for humans and AI agents",
|
||||||
@@ -10,51 +11,34 @@ export const metadata: Metadata = {
|
|||||||
"A content-first knowledge base. Humans read the Web UI; AI agents use the MCP server. Both share one Core.",
|
"A content-first knowledge base. Humans read the Web UI; AI agents use the MCP server. Both share one Core.",
|
||||||
};
|
};
|
||||||
|
|
||||||
const SECTIONS = [
|
|
||||||
{ id: "docs", label: "Documentation", icon: "📄" },
|
|
||||||
{ id: "writeups", label: "Writeups", icon: "📝" },
|
|
||||||
{ id: "research", label: "Research", icon: "🔬" },
|
|
||||||
{ id: "notes", label: "Notes", icon: "📌" },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: Readonly<{
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="en" className="h-full scroll-smooth">
|
<html lang="en" className="h-full scroll-smooth">
|
||||||
<body className="min-h-screen bg-[#08090a] text-[#e2e4e7] font-inter">
|
<body className="min-h-screen bg-[#08090a] text-[#e2e4e7] font-inter">
|
||||||
|
<div hidden>
|
||||||
|
{/* hidden aria-live container for screen readers */}
|
||||||
|
<div id="a11y-live-region" aria-live="polite" aria-atomic="true" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<header className="sticky top-0 z-20 border-b border-[#1f2022]">
|
<header className="sticky top-0 z-20 border-b border-[#1f2022]">
|
||||||
<div className="mx-auto max-w-7xl px-4 h-14 flex items-center justify-between">
|
<div className="mx-auto max-w-7xl px-4 h-14 flex items-center justify-between">
|
||||||
<Link href="/" className="font-medium text-[#f7f8f8] text-lg">
|
<Link href="/" className="font-medium text-[#f7f8f8] text-lg">
|
||||||
MCPedia
|
MCPedia
|
||||||
</Link>
|
</Link>
|
||||||
<nav className="flex items-center gap-6 text-sm">
|
<nav className="flex items-center gap-6 text-sm">
|
||||||
<Link
|
{SECTIONS.map((s) => (
|
||||||
href="/docs"
|
<Link
|
||||||
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
key={s.id}
|
||||||
>
|
href={`/${s.id}`}
|
||||||
Docs
|
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
||||||
</Link>
|
>
|
||||||
<Link
|
{s.label}
|
||||||
href="/writeups"
|
</Link>
|
||||||
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
))}
|
||||||
>
|
|
||||||
Writeups
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/research"
|
|
||||||
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
|
||||||
>
|
|
||||||
Research
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/notes"
|
|
||||||
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
|
||||||
>
|
|
||||||
Notes
|
|
||||||
</Link>
|
|
||||||
<Link
|
<Link
|
||||||
href="/search"
|
href="/search"
|
||||||
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
||||||
@@ -74,11 +58,9 @@ export default function RootLayout({
|
|||||||
|
|
||||||
<div className="mx-auto max-w-7xl">
|
<div className="mx-auto max-w-7xl">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
{/* Sticky sidebar for doc navigation */}
|
|
||||||
<aside className="hidden xl:block w-64 shrink-0 border-r border-[#1f2022]">
|
<aside className="hidden xl:block w-64 shrink-0 border-r border-[#1f2022]">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main className="flex-1 min-w-0">
|
<main className="flex-1 min-w-0">
|
||||||
<div className="px-8 py-10 max-w-4xl mx-auto lg:max-w-5xl xl:max-w-6xl">
|
<div className="px-8 py-10 max-w-4xl mx-auto lg:max-w-5xl xl:max-w-6xl">
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
+43
-66
@@ -1,21 +1,9 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { listDocuments } from "@mcpedia/core";
|
import { listDocuments } from "@mcpedia/core";
|
||||||
import type { DocSection } from "@mcpedia/core";
|
import { SECTIONS } from "@mcpedia/config/sections";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
const SECTIONS: { id: DocSection; label: string; icon: string; desc: string }[] = [
|
|
||||||
{
|
|
||||||
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." },
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a hierarchical folder tree from a flat list of document paths.
|
* Build a hierarchical folder tree from a flat list of document paths.
|
||||||
* Each tree node is either a folder (has children) or a leaf doc.
|
* Each tree node is either a folder (has children) or a leaf doc.
|
||||||
@@ -32,21 +20,6 @@ function buildFolderTree(paths: string[], section: string): TreeNode[] {
|
|||||||
const tree: TreeNode[] = [];
|
const tree: TreeNode[] = [];
|
||||||
const base = `${section}/`;
|
const base = `${section}/`;
|
||||||
|
|
||||||
// Build a map of path → title (leaf docs only)
|
|
||||||
// We don't have titles here, so we use the last path segment as display name
|
|
||||||
const pathToTitle = new Map<string, string>();
|
|
||||||
for (const p of paths) {
|
|
||||||
const rel = p.startsWith(base) ? p.slice(base.length) : p;
|
|
||||||
const cleanPath = rel.replace(/\.md$/, "");
|
|
||||||
const parts = cleanPath.split("/");
|
|
||||||
const leafName = parts[parts.length - 1];
|
|
||||||
const title = leafName
|
|
||||||
.split(/[-_]/)
|
|
||||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
||||||
.join(" ");
|
|
||||||
pathToTitle.set(cleanPath, title);
|
|
||||||
}
|
|
||||||
|
|
||||||
const addPath = (cleanPath: string) => {
|
const addPath = (cleanPath: string) => {
|
||||||
const parts = cleanPath.split("/");
|
const parts = cleanPath.split("/");
|
||||||
let current = tree;
|
let current = tree;
|
||||||
@@ -71,9 +44,11 @@ function buildFolderTree(paths: string[], section: string): TreeNode[] {
|
|||||||
|
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
node.isLeaf = true;
|
node.isLeaf = true;
|
||||||
node.title = pathToTitle.get(cleanPath) ?? part;
|
node.title = part
|
||||||
|
.split(/[-_]/)
|
||||||
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||||
|
.join(" ");
|
||||||
} else if (!node.title) {
|
} else if (!node.title) {
|
||||||
// Folder title: capitalize the folder name
|
|
||||||
node.title = part
|
node.title = part
|
||||||
.split(/[-_]/)
|
.split(/[-_]/)
|
||||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||||
@@ -126,17 +101,16 @@ interface SectionTreeProps {
|
|||||||
pathname: string;
|
pathname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function SectionTree({ section, docPaths, pathname }: SectionTreeProps) {
|
function SectionTree({ section, docPaths, pathname }: SectionTreeProps) {
|
||||||
const tree = buildFolderTree(docPaths.filter((p) => p.startsWith(`${section}/`)), section);
|
const tree = buildFolderTree(docPaths.filter((p) => p.startsWith(`${section}/`)), section);
|
||||||
const sectionInfo = SECTIONS.find((s) => s.id === section)!;
|
const sectionInfo = SECTIONS.find((s) => s.id === section);
|
||||||
|
if (!sectionInfo) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-1.5 mb-2">
|
<div className="flex items-center gap-1.5 mb-2">
|
||||||
<span className="text-xl">{sectionInfo.icon}</span>
|
<span className="text-xl">{sectionInfo.icon}</span>
|
||||||
<h3 className="font-medium text-[#f7f8f8] group-hover:text-[#7170ff] transition-colors">
|
<h3 className="font-medium text-[#f7f8f8]">{sectionInfo.label}</h3>
|
||||||
{sectionInfo.label}
|
|
||||||
</h3>
|
|
||||||
</div>
|
</div>
|
||||||
{tree.length > 0 ? (
|
{tree.length > 0 ? (
|
||||||
renderTree(tree, pathname)
|
renderTree(tree, pathname)
|
||||||
@@ -244,38 +218,41 @@ export default async function HomePage() {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
{recent.map((d) => (
|
{recent.map((d) => {
|
||||||
<Link
|
const sInfo = SECTIONS.find((s) => s.id === d.section);
|
||||||
key={d.slug}
|
return (
|
||||||
href={`/${d.slug}`}
|
<Link
|
||||||
className="group block bg-[#0f1011] border border-[#1f2022] rounded-lg p-4 hover:border-[#5e6ad2]/40 hover:bg-[#131415] transition-all duration-200"
|
key={d.slug}
|
||||||
>
|
href={`/${d.slug}`}
|
||||||
<div className="flex items-start justify-between gap-2 mb-2">
|
className="group block bg-[#0f1011] border border-[#1f2022] rounded-lg p-4 hover:border-[#5e6ad2]/40 hover:bg-[#131415] transition-all duration-200"
|
||||||
<span className="text-xl">
|
>
|
||||||
{SECTIONS.find((s) => s.id === d.section)?.icon || "📄"}
|
<div className="flex items-start justify-between gap-2 mb-2">
|
||||||
</span>
|
<span className="text-xl">
|
||||||
<time className="text-xs text-[#62666d]">
|
{sInfo?.icon || "📄"}
|
||||||
{new Date(d.updatedAt).toLocaleDateString(undefined, {
|
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
})}
|
|
||||||
</time>
|
|
||||||
</div>
|
|
||||||
<h3 className="font-medium text-[#f7f8f8] group-hover:text-[#7170ff] transition-colors line-clamp-1">
|
|
||||||
{d.title}
|
|
||||||
</h3>
|
|
||||||
<div className="mt-2 flex flex-wrap gap-1">
|
|
||||||
{d.tags.slice(0, 3).map((t) => (
|
|
||||||
<span
|
|
||||||
key={t}
|
|
||||||
className="text-xs px-1.5 py-0.5 bg-[#191a1b] border border-[#23252a] rounded text-[#d0d6e0]"
|
|
||||||
>
|
|
||||||
#{t}
|
|
||||||
</span>
|
</span>
|
||||||
))}
|
<time className="text-xs text-[#62666d]">
|
||||||
</div>
|
{new Date(d.updatedAt).toLocaleDateString(undefined, {
|
||||||
</Link>
|
month: "short",
|
||||||
))}
|
day: "numeric",
|
||||||
|
})}
|
||||||
|
</time>
|
||||||
|
</div>
|
||||||
|
<h3 className="font-medium text-[#f7f8f8] group-hover:text-[#7170ff] transition-colors line-clamp-1">
|
||||||
|
{d.title}
|
||||||
|
</h3>
|
||||||
|
<div className="mt-2 flex flex-wrap gap-1">
|
||||||
|
{d.tags.slice(0, 3).map((t) => (
|
||||||
|
<span
|
||||||
|
key={t}
|
||||||
|
className="text-xs px-1.5 py-0.5 bg-[#191a1b] border border-[#23252a] rounded text-[#d0d6e0]"
|
||||||
|
>
|
||||||
|
#{t}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/index.ts",
|
||||||
|
"./sections": "./src/sections.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mcpedia/types": "workspace:*"
|
"@mcpedia/types": "workspace:*"
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export const CONTENT_ROOT =
|
|||||||
process.env.CONTENT_ROOT ?? resolve(REPO_ROOT, "content");
|
process.env.CONTENT_ROOT ?? resolve(REPO_ROOT, "content");
|
||||||
|
|
||||||
export const DATABASE_URL = process.env.DATABASE_URL ?? "";
|
export const DATABASE_URL = process.env.DATABASE_URL ?? "";
|
||||||
|
|
||||||
export const EMBED_BASE_URL = process.env.EMBED_BASE_URL ?? "";
|
export const EMBED_BASE_URL = process.env.EMBED_BASE_URL ?? "";
|
||||||
export const EMBED_API_KEY = process.env.EMBED_API_KEY ?? "";
|
export const EMBED_API_KEY = process.env.EMBED_API_KEY ?? "";
|
||||||
export const EMBED_MODEL = process.env.EMBED_MODEL ?? "";
|
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).
|
// 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_URL = process.env.REDIS_URL ?? "redis://100.121.180.82:6379";
|
||||||
export const REDIS_PASSWORD = process.env.REDIS_PASSWORD ?? "";
|
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";
|
export const QUEUE_PREFIX = process.env.QUEUE_PREFIX ?? "mcpedia";
|
||||||
|
|
||||||
// Phase 4: git-sync webhook shared secret. The API /hooks/* endpoints require
|
// Phase 4: git-sync webhook shared secret.
|
||||||
// this header (x-webhook-secret) to match, so an open port can't trigger reindex.
|
|
||||||
export const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
|
export const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
|
||||||
|
|
||||||
// Phase 11: Admin password for web-based CRUD (create/update/delete documents).
|
// Phase 11: Admin password for web-based CRUD.
|
||||||
// Used by the Web UI login flow. MCP/API writes still use WEBHOOK_SECRET.
|
|
||||||
export const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD ?? "";
|
export const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD ?? "";
|
||||||
|
|
||||||
// NOTE: we deliberately do NOT throw here if DATABASE_URL is empty. Throwing at
|
// Phase 14: Section registry — re-exported from a Node-free module so client
|
||||||
// import time breaks `next build` (SSG data collection imports config before
|
// components can safely import SECTIONS without pulling in node:fs.
|
||||||
// any .env is present) and any runtime-injected env (containers/systemd set env
|
export { SECTIONS, SECTIONS_BY_ID, SECTION_IDS, type SectionConfig } from "./sections";
|
||||||
// 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
|
// NOTE: we deliberately do NOT throw here if DATABASE_URL is empty.
|
||||||
// error at runtime — not a cryptic build failure.
|
// Throwing at import time breaks `next build` SSG and any runtime-injected env.
|
||||||
|
|||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user