3
3
// See the LICENSE file in the project root for more information
4
4
5
5
using System . IO . Abstractions ;
6
+ using System . Text . Json ;
6
7
using Elastic . Documentation ;
7
8
using Elastic . Documentation . Configuration . Builder ;
8
9
using Elastic . Documentation . Legacy ;
@@ -113,6 +114,11 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
113
114
fullNavigationRenderResult
114
115
) ;
115
116
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
+
116
122
117
123
var slice = Page . Index . Create ( new IndexViewModel
118
124
{
@@ -124,12 +130,11 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
124
130
TitleRaw = markdown . TitleRaw ?? "[TITLE NOT SET]" ,
125
131
MarkdownHtml = html ,
126
132
PageTocItems = [ .. markdown . PageTableOfContent . Values ] ,
127
- Tree = DocumentationSet . Tree ,
128
133
CurrentDocument = markdown ,
129
134
CurrentNavigationItem = current ,
130
135
PreviousDocument = previous ,
131
136
NextDocument = next ,
132
- Parents = parents ,
137
+ Breadcrumbs = breadcrumbs ,
133
138
NavigationHtml = navigationHtmlRenderResult . Html ,
134
139
NavigationFileName = navigationFileName ,
135
140
UrlPathPrefix = markdown . UrlPathPrefix ,
@@ -147,7 +152,8 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
147
152
LegacyPages = legacyPages ? . Skip ( 1 ) . ToArray ( ) ,
148
153
VersionDropdownItems = VersionDrownDownItemViewModel . FromLegacyPageMappings ( legacyPages ? . Skip ( 1 ) . ToArray ( ) ) ,
149
154
Products = allProducts ,
150
- VersionsConfig = DocumentationSet . Context . VersionsConfiguration
155
+ VersionsConfig = DocumentationSet . Context . VersionsConfiguration ,
156
+ StructuredBreadcrumbsJson = structuredBreadcrumbsJsonString
151
157
} ) ;
152
158
153
159
return new RenderResult
@@ -159,6 +165,31 @@ private async Task<RenderResult> RenderLayout(MarkdownFile markdown, MarkdownDoc
159
165
160
166
}
161
167
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
+
162
193
public async Task < MarkdownDocument > WriteAsync ( IDirectoryInfo outBaseDir , IFileInfo outputFile , MarkdownFile markdown , IConversionCollector ? collector , Cancel ctx = default )
163
194
{
164
195
if ( outputFile . Directory is { Exists : false } )
@@ -203,5 +234,4 @@ public record RenderResult
203
234
public required string Html { get ; init ; }
204
235
public required string FullNavigationPartialHtml { get ; init ; }
205
236
public required string NavigationFileName { get ; init ; }
206
-
207
237
}
0 commit comments