33// See the LICENSE file in the project root for more information
44
55using System . IO . Abstractions ;
6+ using System . Text . Json ;
67using Elastic . Documentation ;
78using Elastic . Documentation . Configuration . Builder ;
89using Elastic . Documentation . Legacy ;
@@ -113,6 +114,11 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
113114 fullNavigationRenderResult
114115 ) ;
115116
117+ //TODO should we even distinctby
118+ var breadcrumbs = parents . Reverse ( ) . DistinctBy ( p => p . Url ) . ToArray ( ) ;
119+ var breadcrumbsList = CreateStructuredBreadcrumbsData ( markdown , breadcrumbs ) ;
120+ var structuredBreadcrumbsJsonString = JsonSerializer . Serialize ( breadcrumbsList , BreadcrumbsContext . Default . BreadcrumbsList ) ;
121+
116122
117123 var slice = Page . Index . Create ( new IndexViewModel
118124 {
@@ -124,12 +130,11 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
124130 TitleRaw = markdown . TitleRaw ?? "[TITLE NOT SET]" ,
125131 MarkdownHtml = html ,
126132 PageTocItems = [ .. markdown . PageTableOfContent . Values ] ,
127- Tree = DocumentationSet . Tree ,
128133 CurrentDocument = markdown ,
129134 CurrentNavigationItem = current ,
130135 PreviousDocument = previous ,
131136 NextDocument = next ,
132- Parents = parents ,
137+ Breadcrumbs = breadcrumbs ,
133138 NavigationHtml = navigationHtmlRenderResult . Html ,
134139 NavigationFileName = navigationFileName ,
135140 UrlPathPrefix = markdown . UrlPathPrefix ,
@@ -147,7 +152,8 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
147152 LegacyPages = legacyPages ? . Skip ( 1 ) . ToArray ( ) ,
148153 VersionDropdownItems = VersionDrownDownItemViewModel . FromLegacyPageMappings ( legacyPages ? . Skip ( 1 ) . ToArray ( ) ) ,
149154 Products = allProducts ,
150- VersionsConfig = DocumentationSet . Context . VersionsConfiguration
155+ VersionsConfig = DocumentationSet . Context . VersionsConfiguration ,
156+ StructuredBreadcrumbsJson = structuredBreadcrumbsJsonString
151157 } ) ;
152158
153159 return new RenderResult
@@ -159,6 +165,31 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
159165
160166 }
161167
168+ private BreadcrumbsList CreateStructuredBreadcrumbsData ( MarkdownFile markdown , INavigationItem [ ] crumbs )
169+ {
170+ List < BreadcrumbListItem > breadcrumbItems = [ ] ;
171+ var position = 1 ;
172+ // Add parents
173+ breadcrumbItems . AddRange ( crumbs . Select ( parent => new BreadcrumbListItem
174+ {
175+ Position = position ++ ,
176+ Name = parent . NavigationTitle ,
177+ Item = new Uri ( DocumentationSet . Context . CanonicalBaseUrl ?? new Uri ( "http://localhost" ) , Path . Combine ( DocumentationSet . Context . UrlPathPrefix ?? string . Empty , parent . Url ) ) . ToString ( )
178+ } ) ) ;
179+ // Add current page
180+ breadcrumbItems . Add ( new BreadcrumbListItem
181+ {
182+ Position = position ,
183+ Name = markdown . Title ?? markdown . NavigationTitle ,
184+ Item = null ,
185+ } ) ;
186+ var breadcrumbsList = new BreadcrumbsList
187+ {
188+ ItemListElement = breadcrumbItems
189+ } ;
190+ return breadcrumbsList ;
191+ }
192+
162193 public async Task < MarkdownDocument > WriteAsync ( IDirectoryInfo outBaseDir , IFileInfo outputFile , MarkdownFile markdown , IConversionCollector ? collector , Cancel ctx = default )
163194 {
164195 if ( outputFile . Directory is { Exists : false } )
@@ -203,5 +234,4 @@ public record RenderResult
203234 public required string Html { get ; init ; }
204235 public required string FullNavigationPartialHtml { get ; init ; }
205236 public required string NavigationFileName { get ; init ; }
206-
207237}
0 commit comments