5
5
using System . IO . Abstractions ;
6
6
using System . Xml . Linq ;
7
7
using Elastic . Documentation . Site . Navigation ;
8
+ using Elastic . Markdown . Extensions . DetectionRules ;
8
9
using Elastic . Markdown . IO . Navigation ;
9
10
10
11
namespace Documentation . Assembler . Building ;
@@ -21,25 +22,32 @@ public void Generate()
21
22
{
22
23
var flattenedNavigationItems = GetNavigationItems ( navigationItems ) ;
23
24
24
- var doc = new XDocument ( )
25
+ var doc = new XDocument
25
26
{
26
- Declaration = new XDeclaration ( "1.0" , "utf-8" , "yes" ) ,
27
+ Declaration = new XDeclaration ( "1.0" , "utf-8" , "yes" )
27
28
} ;
28
29
30
+ XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9" ;
31
+
29
32
var currentDate = DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:sszzz" ) ;
30
33
var root = new XElement (
31
- "urlset" ,
32
- new XAttribute ( "xmlns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ,
33
- flattenedNavigationItems
34
- . OfType < FileNavigationItem > ( )
35
- . Select ( n => n . Model . Url )
36
- . Distinct ( )
37
- . Select ( u => new Uri ( BaseUri , u ) )
38
- . Select ( u => new XElement ( "url" , [
39
- new XElement ( "loc" , u ) ,
40
- new XElement ( "lastmod" , currentDate )
41
- ] ) )
42
- ) ;
34
+ ns + "urlset" ,
35
+ new XAttribute ( "xmlns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ,
36
+ flattenedNavigationItems
37
+ . Select ( n => n switch
38
+ {
39
+ DocumentationGroup group => ( group . Index . Url , NavigationItem : group ) ,
40
+ FileNavigationItem file => ( file . Model . Url , NavigationItem : file as INavigationItem ) ,
41
+ _ => throw new Exception ( $ "Unhandled navigation item type: { n . GetType ( ) } ")
42
+ } )
43
+ . Select ( n => n . Url )
44
+ . Distinct ( )
45
+ . Select ( u => new Uri ( BaseUri , u ) )
46
+ . Select ( u => new XElement ( ns + "url" , [
47
+ new XElement ( ns + "loc" , u ) ,
48
+ new XElement ( ns + "lastmod" , currentDate )
49
+ ] ) )
50
+ ) ;
43
51
44
52
doc . Add ( root ) ;
45
53
@@ -55,13 +63,24 @@ private static IReadOnlyCollection<INavigationItem> GetNavigationItems(IReadOnly
55
63
switch ( item )
56
64
{
57
65
case FileNavigationItem file :
66
+ // these are hidden from the navigation programatically.
67
+ // TODO find a cleaner way to model this.
68
+ if ( item . Hidden && file . Model is not DetectionRuleFile )
69
+ continue ;
58
70
result . Add ( file ) ;
59
71
break ;
60
72
case DocumentationGroup group :
73
+ if ( item . Hidden )
74
+ continue ;
75
+
61
76
result . AddRange ( GetNavigationItems ( group . NavigationItems ) ) ;
77
+ result . Add ( group ) ;
62
78
break ;
79
+ default :
80
+ throw new Exception ( $ "Unhandled navigation item type: { item . GetType ( ) } ") ;
63
81
}
64
82
}
83
+
65
84
return result ;
66
85
}
67
86
}
0 commit comments