2
2
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
3
// See the LICENSE file in the project root for more information
4
4
5
- namespace Elastic . Markdown . IO ;
5
+ using Elastic . Markdown . IO . Configuration ;
6
6
7
- public class DocumentationFolder
7
+ namespace Elastic . Markdown . IO . Navigation ;
8
+
9
+ public interface INavigationItem
10
+ {
11
+ int Order { get ; }
12
+ int Depth { get ; }
13
+ }
14
+
15
+ public record GroupNavigation ( int Order , int Depth , DocumentationGroup Group ) : INavigationItem ;
16
+ public record FileNavigation ( int Order , int Depth , MarkdownFile File ) : INavigationItem ;
17
+
18
+
19
+ public class DocumentationGroup
8
20
{
9
21
public MarkdownFile ? Index { get ; set ; }
10
22
11
- public List < MarkdownFile > FilesInOrder { get ; }
12
- public List < DocumentationFolder > GroupsInOrder { get ; }
23
+ private IReadOnlyCollection < MarkdownFile > FilesInOrder { get ; }
24
+
25
+ private IReadOnlyCollection < DocumentationGroup > GroupsInOrder { get ; }
26
+
27
+ public IReadOnlyCollection < INavigationItem > NavigationItems { get ; }
13
28
14
- public required DocumentationFolder ? Parent { get ; init ; }
29
+ public required DocumentationGroup ? Parent { get ; init ; }
15
30
16
31
private HashSet < MarkdownFile > OwnFiles { get ; }
17
32
18
- public int Level { get ; }
33
+ public int Depth { get ; }
19
34
20
- public DocumentationFolder (
35
+ public DocumentationGroup (
21
36
IReadOnlyCollection < ITocItem > toc ,
22
37
IDictionary < string , DocumentationFile > lookup ,
23
38
IDictionary < string , DocumentationFile [ ] > folderLookup ,
24
- int level = 0 ,
39
+ int depth = 0 ,
25
40
MarkdownFile ? index = null
26
41
)
27
42
{
28
- Level = level ;
29
- var foundIndex = ProcessTocItems ( toc , lookup , folderLookup , level , out var groupsInOrder , out var filesInOrder ) ;
43
+ Depth = depth ;
44
+ var foundIndex = ProcessTocItems ( toc , lookup , folderLookup , depth , out var groups , out var files , out var navigationItems ) ;
30
45
31
- GroupsInOrder = groupsInOrder ;
32
- FilesInOrder = filesInOrder ;
46
+ GroupsInOrder = groups ;
47
+ FilesInOrder = files ;
48
+ NavigationItems = navigationItems ;
33
49
Index = index ?? foundIndex ;
34
50
35
51
if ( Index is not null )
@@ -42,15 +58,17 @@ public DocumentationFolder(
42
58
IReadOnlyCollection < ITocItem > toc ,
43
59
IDictionary < string , DocumentationFile > lookup ,
44
60
IDictionary < string , DocumentationFile [ ] > folderLookup ,
45
- int level ,
46
- out List < DocumentationFolder > groupsInOrder ,
47
- out List < MarkdownFile > filesInOrder
61
+ int depth ,
62
+ out List < DocumentationGroup > groups ,
63
+ out List < MarkdownFile > files ,
64
+ out List < INavigationItem > navigationItems
48
65
)
49
66
{
50
- groupsInOrder = [ ] ;
51
- filesInOrder = [ ] ;
52
- MarkdownFile ? index = null ;
53
- foreach ( var tocItem in toc )
67
+ groups = [ ] ;
68
+ navigationItems = [ ] ;
69
+ files = [ ] ;
70
+ MarkdownFile ? indexFile = null ;
71
+ foreach ( var ( tocItem , index ) in toc . Select ( ( t , i ) => ( t , i ) ) )
54
72
{
55
73
if ( tocItem is FileReference file )
56
74
{
@@ -61,17 +79,19 @@ out List<MarkdownFile> filesInOrder
61
79
62
80
if ( file . Children . Count > 0 && d is MarkdownFile virtualIndex )
63
81
{
64
- var group = new DocumentationFolder ( file . Children , lookup , folderLookup , level + 1 , virtualIndex )
82
+ var group = new DocumentationGroup ( file . Children , lookup , folderLookup , depth + 1 , virtualIndex )
65
83
{
66
84
Parent = this
67
85
} ;
68
- groupsInOrder . Add ( group ) ;
86
+ groups . Add ( group ) ;
87
+ navigationItems . Add ( new GroupNavigation ( index , depth , group ) ) ;
69
88
continue ;
70
89
}
71
90
72
- filesInOrder . Add ( md ) ;
91
+ files . Add ( md ) ;
92
+ navigationItems . Add ( new FileNavigation ( index , depth , md ) ) ;
73
93
if ( file . Path . EndsWith ( "index.md" ) && d is MarkdownFile i )
74
- index ??= i ;
94
+ indexFile ??= i ;
75
95
}
76
96
else if ( tocItem is FolderReference folder )
77
97
{
@@ -84,15 +104,16 @@ out List<MarkdownFile> filesInOrder
84
104
. ToArray ( ) ;
85
105
}
86
106
87
- var group = new DocumentationFolder ( children , lookup , folderLookup , level + 1 )
107
+ var group = new DocumentationGroup ( children , lookup , folderLookup , depth + 1 )
88
108
{
89
109
Parent = this
90
110
} ;
91
- groupsInOrder . Add ( group ) ;
111
+ groups . Add ( group ) ;
112
+ navigationItems . Add ( new GroupNavigation ( index , depth , group ) ) ;
92
113
}
93
114
}
94
115
95
- return index ?? filesInOrder . FirstOrDefault ( ) ;
116
+ return indexFile ?? files . FirstOrDefault ( ) ;
96
117
}
97
118
98
119
public bool HoldsCurrent ( MarkdownFile current ) =>
0 commit comments