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,7 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
113114 fullNavigationRenderResult
114115 ) ;
115116
117+ var structuredBreadcrumbsJson = CreateStructuredBreadcrumbsData ( markdown , parents ) ;
116118
117119 var slice = Page . Index . Create ( new IndexViewModel
118120 {
@@ -147,7 +149,8 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
147149 LegacyPages = legacyPages ? . Skip ( 1 ) . ToArray ( ) ,
148150 VersionDropdownItems = VersionDrownDownItemViewModel . FromLegacyPageMappings ( legacyPages ? . Skip ( 1 ) . ToArray ( ) ) ,
149151 Products = allProducts ,
150- VersionsConfig = DocumentationSet . Context . VersionsConfiguration
152+ VersionsConfig = DocumentationSet . Context . VersionsConfiguration ,
153+ StructuredBreadcrumbsJson = structuredBreadcrumbsJson
151154 } ) ;
152155
153156 return new RenderResult
@@ -159,6 +162,33 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
159162
160163 }
161164
165+ private string CreateStructuredBreadcrumbsData ( MarkdownFile markdown , INavigationItem [ ] parents )
166+ {
167+ List < BreadcrumbListItem > breadcrumbItems = [ ] ;
168+ var position = 1 ;
169+ var crumbs = parents . Reverse ( ) . DistinctBy ( i => i . Url ) . ToList ( ) ;
170+ // Add parents
171+ breadcrumbItems . AddRange ( crumbs . Select ( ( parent ) => new BreadcrumbListItem
172+ {
173+ Position = position ++ ,
174+ Name = parent . NavigationTitle ,
175+ Item = new Uri ( DocumentationSet . Context . CanonicalBaseUrl ?? new Uri ( "http://localhost" ) , Path . Combine ( DocumentationSet . Context . UrlPathPrefix ?? string . Empty , parent . Url ) ) . ToString ( )
176+ } ) ) ;
177+ // Add current page
178+ breadcrumbItems . Add ( new BreadcrumbListItem
179+ {
180+ Position = position ,
181+ Name = markdown . Title ?? "[TITLE NOT SET]" ,
182+ Item = null ,
183+ } ) ;
184+ var breadcrumbsList = new BreadcrumbsList
185+ {
186+ ItemListElement = breadcrumbItems
187+ } ;
188+ var structuredBreadcrumbsJson = JsonSerializer . Serialize ( breadcrumbsList , BreadcrumbsContext . Default . BreadcrumbsList ) ;
189+ return structuredBreadcrumbsJson . Trim ( ) ;
190+ }
191+
162192 public async Task < MarkdownDocument > WriteAsync ( IDirectoryInfo outBaseDir , IFileInfo outputFile , MarkdownFile markdown , IConversionCollector ? collector , Cancel ctx = default )
163193 {
164194 if ( outputFile . Directory is { Exists : false } )
@@ -203,5 +233,4 @@ public record RenderResult
203233 public required string Html { get ; init ; }
204234 public required string FullNavigationPartialHtml { get ; init ; }
205235 public required string NavigationFileName { get ; init ; }
206-
207236}
0 commit comments