'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import type { ReactNode } from 'react'; import { pageSupportsEngine } from '@embedpdf/docs-kit'; import { DOCS_SITE } from '@/docs-site'; import { docsIntegrationFromPath, docsIntegrationHref } from '@/lib/docs-integrations'; import { useConfig } from './config-provider'; import { DocsProductSwitcher } from './docs-product-switcher'; import { IntegrationSwitcher } from './integration'; import { MethodBadge } from './method-badge'; type TreeItem = { name: string; route?: string; title: ReactNode; /** * Page frontmatter; API reference pages carry their HTTP `method` * and — for API-token-only operations — `audience: operator` here. */ frontMatter?: { method?: string; audience?: string; engines?: string[] }; children?: TreeItem[]; }; /** * A section is operator surface when every page in it is — on managed * CloudPDF those sections (Deployment, Tenants) belong to the platform. */ function isOperatorSection(item: TreeItem): boolean { const pages = (item.children ?? []).filter((child) => child.route); return pages.length > 0 && pages.every((child) => child.frontMatter?.audience === 'operator'); } function SidebarLink({ item, pathname }: { item: TreeItem; pathname: string }) { if (!item.route) return null; // Content routes are integration-less; rendered hrefs carry the active // integration so every crawlable link is a concrete destination. const integration = docsIntegrationFromPath(pathname); const href = integration ? docsIntegrationHref(item.route, integration) : item.route; const active = pathname === href; const method = item.frontMatter?.method; return ( {method ? : null} {item.title} ); } function SidebarTree({ items, pathname }: { items: TreeItem[]; pathname: string }) { // Rung 4 of the fork ladder: pages declaring `engines:` they don't // support on this site simply don't exist in its navigation. const visible = items.filter((item) => pageSupportsEngine(item.frontMatter, DOCS_SITE.engine)); return ( <> {visible.map((item) => { const hasChildren = Boolean(item.children && item.children.length > 0); if (hasChildren) { return (

{item.title} {isOperatorSection(item) ? ( Self-hosted ) : null}

); } return ; })} ); } /** * Whether this route has docs navigation at all — false on standalone pages * such as the /docs landing. The desktop rail and the mobile drawer must * agree, so both ask this rather than re-deriving the rules. */ export function useHasDocsNav() { const { docsDirectories, activeType } = useConfig(); if (activeType === 'page') return false; return Boolean(docsDirectories && docsDirectories.length > 0); } /** The navigation itself, free of any rail chrome — shared by both layouts. */ export function DocsNav() { const { docsDirectories } = useConfig(); const pathname = usePathname(); return ( <> ); } export function Sidebar() { const hasNav = useHasDocsNav(); if (!hasNav) return null; return ( ); }