diff --git a/src/layouts/DocsLayout.astro b/src/layouts/DocsLayout.astro index 0b8f0682..eb7409ac 100644 --- a/src/layouts/DocsLayout.astro +++ b/src/layouts/DocsLayout.astro @@ -10,6 +10,7 @@ import CopyPageDropdown from '../components/CopyPageDropdown.astro'; import PageFeedback from '../components/PageFeedback.tsx'; import GiscusComments from '../components/GiscusComments.tsx'; import FastNav from '../components/FastNav.astro'; +import { getFirstChildHrefForPath } from '../lib/navigation'; interface Props { frontmatter: { @@ -57,11 +58,19 @@ function breadcrumbHasPage(segments: string[], upTo: number): boolean { ); } -const breadcrumbs = pathSegments.map((segment, i) => ({ - name: segment.replace(/-/g, ' ').replace(/\b\w/g, (c: string) => c.toUpperCase()), - url: `https://docs.futureagi.com/${pathSegments.slice(0, i + 1).join('/')}`, - hasPage: breadcrumbHasPage(pathSegments, i), -})); +const breadcrumbs = pathSegments.map((segment, i) => { + const relPath = '/' + pathSegments.slice(0, i + 1).join('/'); + const hasPage = breadcrumbHasPage(pathSegments, i); + // If no page exists at this URL but children exist in nav, fall back to the + // first child so the breadcrumb segment stays clickable. + const fallbackHref = hasPage ? undefined : getFirstChildHrefForPath(relPath); + return { + name: segment.replace(/-/g, ' ').replace(/\b\w/g, (c: string) => c.toUpperCase()), + url: `https://docs.futureagi.com${relPath}`, + linkHref: hasPage ? relPath : fallbackHref, + hasLink: hasPage || Boolean(fallbackHref), + }; +}); // Override last breadcrumb with actual page title if (breadcrumbs.length > 0) { breadcrumbs[breadcrumbs.length - 1].name = frontmatter.title; @@ -98,8 +107,8 @@ if (breadcrumbs.length > 0) {