| 1 | "use client"; |
| 2 | |
| 3 | import Link from "next/link"; |
| 4 | import { usePathname } from "next/navigation"; |
| 5 | import { buildBreadcrumbListJsonLd, resolveDocsBreadcrumbs } from "@/lib/docs-breadcrumbs"; |
| 6 | import { getDocsShell } from "@/lib/i18n/dictionaries"; |
| 7 | import { serializeJsonLd } from "@/lib/json-ld"; |
| 8 | |
| 9 | export function DocsBreadcrumb({ locale }: { locale: string }) { |
| 10 | const pathname = usePathname() ?? `/${locale}/docs`; |
| 11 | const crumbs = resolveDocsBreadcrumbs(locale, pathname); |
| 12 | const jsonLd = buildBreadcrumbListJsonLd(locale, pathname); |
| 13 | const t = getDocsShell(locale); |
| 14 | |
| 15 | return ( |
| 16 | <> |
| 17 | <script |
| 18 | type="application/ld+json" |
| 19 | dangerouslySetInnerHTML={{ __html: serializeJsonLd(jsonLd) }} |
| 20 | /> |
| 21 | <nav className="docs-breadcrumb" aria-label={t.breadcrumbAria}> |
| 22 | <ol> |
| 23 | {crumbs.map((crumb, index) => { |
| 24 | const current = index === crumbs.length - 1; |
| 25 | return ( |
| 26 | <li key={`${crumb.name}-${index}`}> |
| 27 | {current || !crumb.href ? ( |
| 28 | <span aria-current={current ? "page" : undefined}>{crumb.name}</span> |
| 29 | ) : ( |
| 30 | <Link href={crumb.href}>{crumb.name}</Link> |
| 31 | )} |
| 32 | </li> |
| 33 | ); |
| 34 | })} |
| 35 | </ol> |
| 36 | </nav> |
| 37 | </> |
| 38 | ); |
| 39 | } |
| 40 |