diff --git a/src/components/overrides/PageTitle.astro b/src/components/overrides/PageTitle.astro index 7e5e4f8707c621..e514af9bb5a9c3 100644 --- a/src/components/overrides/PageTitle.astro +++ b/src/components/overrides/PageTitle.astro @@ -5,28 +5,81 @@ import Default from "@astrojs/starlight/components/PageTitle.astro"; import { Breadcrumbs } from "astro-breadcrumbs"; import "astro-breadcrumbs/breadcrumbs.css"; -import { Badge, Description, SpotlightAuthorDetails, LastReviewed } from "~/components"; +import { + Badge, + Description, + SpotlightAuthorDetails, + LastReviewed, +} from "~/components"; +import type { ComponentProps } from "astro/types"; +import { getEntry } from "astro:content"; const spotlightDetails = Astro.props.entry.data.spotlight; const updated = Astro.props.entry.data.updated; const badge = Astro.props.entry.data.sidebar?.badge; const summary = Astro.props.entry.data.summary; + +const breadcrumbProps: Record = { + crumbs: [ + { + text: "Products", + href: "/products/", + }, + ], + truncated: true, +}; + +const slug = Astro.props.entry.slug; + +const segments = slug.split("/"); + +for (let i = 0; i < segments.length; i++) { + if (i === 0) { + const entry = await getEntry("products", segments[0]); + + let title = segments[0]; + if (entry) { + title = entry.data.product.title; + } + + breadcrumbProps.crumbs.push({ + text: title, + href: `/${segments[0]}/`, + }); + + continue; + } + + let path = segments.slice(0, i + 1).join("/"); + + const entry = await getEntry("docs", path); + + let title = segments[i]; + if (entry) { + title = entry.data.title; + } + + breadcrumbProps.crumbs.push({ + text: title, + href: `/${segments.join("/")}/`, + }); +} --- - - - + + + @@ -35,19 +88,19 @@ const summary = Astro.props.entry.data.summary; {updated && } { - spotlightDetails && ( - - ) + spotlightDetails && ( + + ) } -{ summary && {summary} } +{summary && {summary}}