@@ -83,30 +83,13 @@ private IReadOnlyCollection<INavigationItem> BuildNavigation(IReadOnlyCollection
83
83
var tocChildren = toc . Children . OfType < TocReference > ( ) . ToArray ( ) ;
84
84
var tocNavigationItems = BuildNavigation ( tocChildren , depth + 1 ) ;
85
85
86
- var allNavigationItems = tree . NavigationItems . Concat ( tocNavigationItems ) ;
87
- var cleanNavigationItems = new List < INavigationItem > ( ) ;
86
+ var allNavigationItems = new List < INavigationItem > ( ) ;
88
87
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 ;
98
88
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 ) ;
108
91
109
- tree . NavigationItems = cleanNavigationItems . OrderBy ( n => n . Order ) . ToArray ( ) ;
92
+ tree . NavigationItems = allNavigationItems . ToArray ( ) ;
110
93
var navigationItem = new TocNavigationItem ( i , depth , tree , toc . Source ) ;
111
94
112
95
list . Add ( navigationItem ) ;
@@ -115,4 +98,29 @@ private IReadOnlyCollection<INavigationItem> BuildNavigation(IReadOnlyCollection
115
98
116
99
return list . ToArray ( ) . AsReadOnly ( ) ;
117
100
}
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
+ }
118
126
}
0 commit comments