'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}