"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; interface Doc { slug: string; title: string; section: 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; /** Client-side sidebar (fetches doc list via /api/docs at runtime). * Client component so `next build` SSG doesn't hit Postgres (CI has no DB). */ export default function Sidebar() { const [docs, setDocs] = useState([]); const pathname = usePathname(); useEffect(() => { fetch("/api/docs") .then((r) => r.json()) .then((data) => { if (Array.isArray(data)) setDocs(data); else if (data?.docs) setDocs(data.docs); }) .catch(() => setDocs([])); }, []); const bySection: Record = {}; for (const doc of docs) { if (!bySection[doc.section]) bySection[doc.section] = []; bySection[doc.section].push(doc); } return ( ); }