'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 { useConfig } from './config-provider'; import { DocsProductSwitcher } from './docs-product-switcher'; import { IntegrationSwitcher } from './integration'; import { docsIntegrationFromPath, docsIntegrationHref } from '@/lib/docs-integrations'; import { docsProductFromPath } from '@/lib/docs-products'; import { V2_ARCHIVE_ORIGIN } from '@/lib/v2-redirects'; type TreeItem = { name: string; route?: string; title: ReactNode; /** Page frontmatter; `engines:` declares engine-axis availability. */ frontMatter?: { engines?: string[] }; children?: TreeItem[]; }; 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; return ( {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}

); } 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(); const pathname = usePathname(); if (activeType === 'page') return false; if (!docsProductFromPath(pathname)) 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 ( <> {/* The 2.x docs live on as a frozen site; this link is the whole version switcher. */} Docs for EmbedPDF 2.x ); } export function Sidebar() { const hasNav = useHasDocsNav(); if (!hasNav) return null; return ( ); }