@@ -5,28 +5,81 @@ import Default from "@astrojs/starlight/components/PageTitle.astro";
55import { Breadcrumbs } from " astro-breadcrumbs" ;
66import " astro-breadcrumbs/breadcrumbs.css" ;
77
8- import { Badge , Description , SpotlightAuthorDetails , LastReviewed } from " ~/components" ;
8+ import {
9+ Badge ,
10+ Description ,
11+ SpotlightAuthorDetails ,
12+ LastReviewed ,
13+ } from " ~/components" ;
14+ import type { ComponentProps } from " astro/types" ;
15+ import { getEntry } from " astro:content" ;
916
1017const spotlightDetails = Astro .props .entry .data .spotlight ;
1118const updated = Astro .props .entry .data .updated ;
1219const badge = Astro .props .entry .data .sidebar ?.badge ;
1320const summary = Astro .props .entry .data .summary ;
21+
22+ const breadcrumbProps: Record <string , any > = {
23+ crumbs: [
24+ {
25+ text: " Products" ,
26+ href: " /products/" ,
27+ },
28+ ],
29+ truncated: true ,
30+ };
31+
32+ const slug = Astro .props .entry .slug ;
33+
34+ const segments = slug .split (" /" );
35+
36+ for (let i = 0 ; i < segments .length ; i ++ ) {
37+ if (i === 0 ) {
38+ const entry = await getEntry (" products" , segments [0 ]);
39+
40+ let title = segments [0 ];
41+ if (entry ) {
42+ title = entry .data .product .title ;
43+ }
44+
45+ breadcrumbProps .crumbs .push ({
46+ text: title ,
47+ href: ` /${segments [0 ]}/ ` ,
48+ });
49+
50+ continue ;
51+ }
52+
53+ let path = segments .slice (0 , i + 1 ).join (" /" );
54+
55+ const entry = await getEntry (" docs" , path );
56+
57+ let title = segments [i ];
58+ if (entry ) {
59+ title = entry .data .title ;
60+ }
61+
62+ breadcrumbProps .crumbs .push ({
63+ text: title ,
64+ href: ` /${segments .join (" /" )}/ ` ,
65+ });
66+ }
1467---
1568
16- <Breadcrumbs linkTextFormat = " capitalized " truncated = { true } >
17- <svg
18- slot =" separator"
19- xmlns =" http://www.w3.org/2000/svg"
20- width =" 24"
21- height =" 24"
22- viewBox =" 0 0 24 24"
23- fill =" none"
24- stroke =" currentColor"
25- stroke-width =" 2"
26- stroke-linecap =" round"
27- stroke-linejoin =" round"
28- ><polyline points =" 9 18 15 12 9 6" ></polyline >
29- </svg >
69+ <Breadcrumbs { ... breadcrumbProps }>
70+ <svg
71+ slot =" separator"
72+ xmlns =" http://www.w3.org/2000/svg"
73+ width =" 24"
74+ height =" 24"
75+ viewBox =" 0 0 24 24"
76+ fill =" none"
77+ stroke =" currentColor"
78+ stroke-width =" 2"
79+ stroke-linecap =" round"
80+ stroke-linejoin =" round"
81+ ><polyline points =" 9 18 15 12 9 6" ></polyline >
82+ </svg >
3083</Breadcrumbs >
3184<Default {... Astro .props } />
3285
@@ -35,19 +88,19 @@ const summary = Astro.props.entry.data.summary;
3588{ updated && <LastReviewed date = { updated } />}
3689
3790{
38- spotlightDetails && (
39- <SpotlightAuthorDetails
40- author = { spotlightDetails .author }
41- platform = { spotlightDetails .author_bio_source }
42- link = { spotlightDetails .author_bio_link }
43- />
44- )
91+ spotlightDetails && (
92+ <SpotlightAuthorDetails
93+ author = { spotlightDetails .author }
94+ platform = { spotlightDetails .author_bio_source }
95+ link = { spotlightDetails .author_bio_link }
96+ />
97+ )
4598}
4699
47- { summary && <Description >{ summary } </Description > }
100+ { summary && <Description >{ summary } </Description >}
48101
49102<style >
50- :root {
51- --color-link-breadcrumbs: var(--sl-color-text-accent);
52- }
103+ :root {
104+ --color-link-breadcrumbs: var(--sl-color-text-accent);
105+ }
53106</style >
0 commit comments