"use client"; import { usePathname } from "next/navigation"; import type { ReactNode } from "react"; import { NAV_GROUPS } from "@/lib/nav"; import { FAMILIES, allSpecs, familyOfSpec, familyTree, type Family } from "@/lib/specs"; /** * The sidebar, broad first, drilling down in place. The four groups are * always shown. Under Specs, the family the current page belongs to unfolds * to its specs, and the spec the page belongs to unfolds to its blocks, so * the sidebar shows where you are and what is beside you without leaving the * page. Rendered on the server too, so the unfolded state is in the HTML. */ function currentFamily(pathname: string): { family?: Family; specSlug?: string } { const parts = pathname.split("/").filter(Boolean); if (parts[0] === "specs" && parts[1]) return { family: FAMILIES.find((f) => f.slug === parts[1]) }; const slug = parts[0] === "docs" && parts[1] ? allSpecs().find((x) => x.doc === `/docs/${parts[1]}`)?.slug : allSpecs().find((x) => x.landing === `/${parts[0]}`)?.slug; if (!slug) return {}; return { family: familyOfSpec(slug), specSlug: slug }; } export function SideNav(): ReactNode { const pathname = usePathname() ?? "/"; const { family: open, specSlug } = currentFamily(pathname); const openParent = specSlug ? allSpecs().find((x) => x.slug === specSlug)?.parent ?? specSlug : undefined; const isCurrent = (href: string): boolean => href === pathname; return ( ); }