@@ -83,30 +83,13 @@ private IReadOnlyCollection<INavigationItem> BuildNavigation(IReadOnlyCollection
8383 var tocChildren = toc . Children . OfType < TocReference > ( ) . ToArray ( ) ;
8484 var tocNavigationItems = BuildNavigation ( tocChildren , depth + 1 ) ;
8585
86- var allNavigationItems = tree . NavigationItems . Concat ( tocNavigationItems ) ;
87- var cleanNavigationItems = new List < INavigationItem > ( ) ;
86+ var allNavigationItems = new List < INavigationItem > ( ) ;
8887 var seenSources = new HashSet < Uri > ( ) ;
89- foreach ( var allNavigationItem in allNavigationItems )
90- {
91- if ( allNavigationItem is not TocNavigationItem tocNav )
92- {
93- cleanNavigationItems . Add ( allNavigationItem ) ;
94- continue ;
95- }
96- if ( seenSources . Contains ( tocNav . Source ) )
97- continue ;
9888
99- if ( ! _assembleSources . TocTopLevelMappings . TryGetValue ( tocNav . Source , out var mapping ) )
100- continue ;
101-
102- if ( mapping . ParentSource != tree . Source )
103- continue ;
104-
105- _ = seenSources . Add ( tocNav . Source ) ;
106- cleanNavigationItems . Add ( allNavigationItem ) ;
107- }
89+ AddNavigationItems ( allNavigationItems , tree . NavigationItems , seenSources , tree ) ;
90+ AddNavigationItems ( allNavigationItems , tocNavigationItems , seenSources , tree ) ;
10891
109- tree . NavigationItems = cleanNavigationItems . OrderBy ( n => n . Order ) . ToArray ( ) ;
92+ tree . NavigationItems = allNavigationItems . ToArray ( ) ;
11093 var navigationItem = new TocNavigationItem ( i , depth , tree , toc . Source ) ;
11194
11295 list . Add ( navigationItem ) ;
@@ -115,4 +98,29 @@ private IReadOnlyCollection<INavigationItem> BuildNavigation(IReadOnlyCollection
11598
11699 return list . ToArray ( ) . AsReadOnly ( ) ;
117100 }
101+
102+ private void AddNavigationItems ( List < INavigationItem > navigationItems , IEnumerable < INavigationItem > ? toAdd , HashSet < Uri > seenSources , TableOfContentsTree tree )
103+ {
104+ if ( toAdd is null )
105+ return ;
106+ foreach ( var navigationItem in toAdd )
107+ {
108+ if ( navigationItem is not TocNavigationItem tocNav )
109+ {
110+ navigationItems . Add ( navigationItem ) ;
111+ continue ;
112+ }
113+ if ( seenSources . Contains ( tocNav . Source ) )
114+ continue ;
115+
116+ if ( ! _assembleSources . TocTopLevelMappings . TryGetValue ( tocNav . Source , out var mapping ) )
117+ continue ;
118+
119+ if ( mapping . ParentSource != tree . Source )
120+ continue ;
121+
122+ _ = seenSources . Add ( tocNav . Source ) ;
123+ navigationItems . Add ( navigationItem ) ;
124+ }
125+ }
118126}
0 commit comments