66using System . IO . Abstractions ;
77using Elastic . Documentation . Configuration . DocSet ;
88using Elastic . Documentation . Extensions ;
9+ using Elastic . Documentation . Links . CrossLinks ;
910using Elastic . Documentation . Navigation . Isolated . Leaf ;
1011
1112namespace Elastic . Documentation . Navigation . Isolated . Node ;
@@ -22,18 +23,21 @@ public class DocumentationSetNavigation<TModel>
2223 where TModel : class , IDocumentationFile
2324{
2425 private readonly IDocumentationFileFactory < TModel > _factory ;
26+ private readonly ICrossLinkResolver _crossLinkResolver ;
2527
2628 public DocumentationSetNavigation (
2729 DocumentationSetFile documentationSet ,
2830 IDocumentationSetContext context ,
2931 IDocumentationFileFactory < TModel > factory ,
3032 IRootNavigationItem < INavigationModel , INavigationItem > ? parent = null ,
3133 IRootNavigationItem < INavigationModel , INavigationItem > ? root = null ,
32- string ? pathPrefix = null
34+ string ? pathPrefix = null ,
35+ ICrossLinkResolver ? crossLinkResolver = null
3336 )
3437 {
3538 _context = context ;
3639 _factory = factory ;
40+ _crossLinkResolver = crossLinkResolver ?? NoopCrossLinkResolver . Instance ;
3741 _pathPrefix = pathPrefix ?? string . Empty ;
3842 // Initialize root properties
3943 _navigationRoot = root ?? this ;
@@ -139,7 +143,7 @@ public DocumentationSetNavigation(
139143 public IReadOnlyCollection < INavigationItem > NavigationItems { get ; private set ; }
140144
141145 void IAssignableChildrenNavigation . SetNavigationItems ( IReadOnlyCollection < INavigationItem > navigationItems ) => SetNavigationItems ( navigationItems ) ;
142- internal void SetNavigationItems ( IReadOnlyCollection < INavigationItem > navigationItems )
146+ private void SetNavigationItems ( IReadOnlyCollection < INavigationItem > navigationItems )
143147 {
144148 var indexNavigation = navigationItems . QueryIndex < TModel > ( this , $ "{ PathPrefix } /index.md", out navigationItems ) ;
145149 Index = indexNavigation ;
@@ -280,19 +284,21 @@ INavigationHomeAccessor homeAccessor
280284 return fileNavigation ;
281285 }
282286
283- private INavigationItem CreateCrossLinkNavigation (
287+ private INavigationItem ? CreateCrossLinkNavigation (
284288 CrossLinkRef crossLinkRef ,
285289 int index ,
286290 INodeNavigationItem < INavigationModel , INavigationItem > ? parent ,
287291 INavigationHomeAccessor homeAccessor
288292 )
289293 {
290294 var title = crossLinkRef . Title ?? crossLinkRef . CrossLinkUri . OriginalString ;
291- var model = new CrossLinkModel ( crossLinkRef . CrossLinkUri , title ) ;
295+ if ( ! _crossLinkResolver . TryResolve ( s => _context . EmitError ( _context . ConfigurationPath , s ) , crossLinkRef . CrossLinkUri , out var resolvedUri ) )
296+ return null ;
297+ var model = new CrossLinkModel ( resolvedUri , title ) ;
292298
293299 return new CrossLinkNavigationLeaf (
294300 model ,
295- crossLinkRef . CrossLinkUri . OriginalString ,
301+ resolvedUri . ToString ( ) ,
296302 crossLinkRef . Hidden ,
297303 parent ,
298304 homeAccessor
0 commit comments