'use client' import { useConfig } from 'nextra-theme-docs' import { usePathname } from 'next/navigation' import Link from 'next/link' import { useState, useEffect } from 'react' import { createPortal } from 'react-dom' import { House, RocketLaunch, Lightning, Cloud, AppWindow, BookOpen, PencilSimple, Brain, Users, Buildings, GraduationCap, ChalkboardTeacher, Stack, Path, Cube, UsersThree, DownloadSimple, Gear, Wrench, ListChecks, Terminal, TreeStructure, GitBranch, Plug, Browser, Database, HardDrives, Key, Envelope, Folder, Lock, ArrowsClockwise, ClockCountdown, ChartBar, Lifebuoy, ShieldCheck, Code, BookBookmark, SlidersHorizontal, ClipboardText, Trophy, CheckCircle, GameController, ChatCircle, ChatDots, ThumbsUp, Kanban, ChalkboardSimple, Microphone, MagnifyingGlass, Certificate, Briefcase, CreditCard, Storefront, ShoppingCart, Receipt, IdentificationBadge, Package, Scroll, } from '@phosphor-icons/react/dist/ssr' const ICON_SIZE = 15 const iconMap = { // Root level '/': House, '/getting-started': RocketLaunch, '/platform': AppWindow, '/enterprise': Briefcase, '/self-hosting': Cloud, '/developers': Code, // Getting Started '/getting-started/quickstart': Lightning, '/getting-started/cloud-vs-self-hosting': Cloud, '/getting-started/key-concepts': BookOpen, // Platform '/platform/courses': BookBookmark, '/platform/editor': PencilSimple, '/platform/ai': Brain, '/platform/users': Users, '/platform/organizations': Buildings, // Platform > Courses '/platform/courses/chapters-and-activities': Stack, '/platform/courses/collections': Folder, '/platform/courses/trails': Path, // Platform > Editor '/platform/editor/blocks': Cube, // Platform > AI '/platform/ai/for-students': GraduationCap, '/platform/ai/for-teachers': ChalkboardTeacher, // Platform > Users '/platform/users/roles-and-permissions': ShieldCheck, '/platform/users/authentication': Key, // Platform > Assignments '/platform/assignments': ClipboardText, '/platform/assignments/grading': CheckCircle, // Platform > Code Execution '/platform/code-execution': Terminal, // Platform > Playgrounds '/platform/playgrounds': GameController, // Platform > Discussions '/platform/discussions': ChatCircle, '/platform/discussions/comments': ChatDots, // Platform > Boards '/platform/boards': ChalkboardSimple, // Platform > Podcasts '/platform/podcasts': Microphone, // Platform > Certifications '/platform/certifications': Certificate, // Platform > Analytics '/platform/analytics': ChartBar, // Platform > Search '/platform/search': MagnifyingGlass, // Platform > Payments '/platform/payments': CreditCard, '/platform/payments/offers': Storefront, '/platform/payments/groups': ShoppingCart, '/platform/payments/enrollments': Receipt, // Platform > Organizations '/platform/organizations/multi-tenancy': TreeStructure, '/platform/organizations/settings': SlidersHorizontal, // Enterprise '/enterprise/sso': IdentificationBadge, '/enterprise/audit-logs': Scroll, '/enterprise/scorm': Package, // Self Hosting '/self-hosting/installation': DownloadSimple, '/self-hosting/configuration': Gear, '/self-hosting/maintenance': Wrench, // Self Hosting > Installation '/self-hosting/installation/requirements': ListChecks, '/self-hosting/installation/quick-install': Lightning, '/self-hosting/installation/cli-reference': Terminal, // Self Hosting > Configuration '/self-hosting/configuration/environment-variables': Code, '/self-hosting/configuration/ai-setup': Brain, '/self-hosting/configuration/email': Envelope, '/self-hosting/configuration/storage': HardDrives, '/self-hosting/configuration/ssl': Lock, // Self Hosting > Maintenance '/self-hosting/maintenance/updates': ArrowsClockwise, '/self-hosting/maintenance/backups': ClockCountdown, '/self-hosting/maintenance/monitoring': ChartBar, '/self-hosting/maintenance/troubleshooting': Lifebuoy, // CLI '/cli': Terminal, '/cli/commands': ListChecks, '/cli/setup-wizard': Lightning, '/cli/dev-mode': Code, '/cli/environment-variables': Gear, // Developers '/developers/architecture': TreeStructure, '/developers/contributing': GitBranch, '/developers/api': Plug, // Developers > Architecture '/developers/architecture/frontend': Browser, '/developers/architecture/backend': Database, '/developers/architecture/services': HardDrives, // Developers > Contributing '/developers/contributing/dev-environment': Terminal, '/developers/contributing/guidelines': BookOpen, // Developers > API '/developers/api/authentication': Key, '/developers/api/endpoints': Plug, } function getIcon(route) { const Icon = iconMap[route] if (!Icon) return null return } function SidebarItem({ item, depth = 0, onNavigate }) { const pathname = usePathname() const isActive = pathname === item.route const hasChildren = item.children && item.children.length > 0 const isChildActive = hasChildren && item.children.some( child => pathname === child.route || pathname?.startsWith(child.route + '/') ) const [open, setOpen] = useState(isChildActive || depth < 1) useEffect(() => { if (isChildActive) setOpen(true) }, [isChildActive]) if (item.type === 'separator') { return (
{typeof item.title === 'string' ? item.title : item.name}
) } if (item.display === 'hidden') return null const title = typeof item.title === 'string' ? item.title : typeof item.title === 'object' && item.title ? item.title : item.name const icon = getIcon(item.route) if (hasChildren) { return (
{open && (
{item.children.map((child, i) => ( ))}
)}
) } return ( {icon && {icon}} {title} ) } function SidebarContent({ onNavigate }) { const config = useConfig() const pathname = usePathname() const { docsDirectories } = config.normalizePagesResult const isDevSection = pathname?.startsWith('/developers') || pathname?.startsWith('/self-hosting') || pathname?.startsWith('/cli') || pathname?.startsWith('/enterprise') const devRoutes = ['/developers', '/self-hosting', '/cli', '/enterprise'] const items = docsDirectories.filter((item) => { const isDev = devRoutes.some(r => item.route?.startsWith(r)) return isDevSection ? isDev : !isDev }) // Enforce sidebar order for dev section const devOrder = ['/developers', '/cli', '/self-hosting', '/enterprise'] items.sort((a, b) => { const aIdx = devOrder.indexOf(a.route) const bIdx = devOrder.indexOf(b.route) if (aIdx !== -1 && bIdx !== -1) return aIdx - bIdx if (aIdx !== -1) return -1 if (bIdx !== -1) return 1 return 0 }) return ( ) } function MobileSidebarPortal({ onNavigate }) { const [mountNode, setMountNode] = useState(null) useEffect(() => { const el = document.getElementById('mobile-sidebar-mount') if (el) setMountNode(el) }, []) if (!mountNode) return null return createPortal(, mountNode) } export default function Sidebar() { return ( <> {/* Desktop sidebar */} {/* Portal into mobile drawer */} ) }