55using System . IO . Abstractions ;
66using System . Xml . Linq ;
77using Elastic . Documentation . Site . Navigation ;
8+ using Elastic . Markdown . Extensions . DetectionRules ;
89using Elastic . Markdown . IO . Navigation ;
910
1011namespace Documentation . Assembler . Building ;
@@ -21,25 +22,32 @@ public void Generate()
2122 {
2223 var flattenedNavigationItems = GetNavigationItems ( navigationItems ) ;
2324
24- var doc = new XDocument ( )
25+ var doc = new XDocument
2526 {
26- Declaration = new XDeclaration ( "1.0" , "utf-8" , "yes" ) ,
27+ Declaration = new XDeclaration ( "1.0" , "utf-8" , "yes" )
2728 } ;
2829
30+ XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9" ;
31+
2932 var currentDate = DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:sszzz" ) ;
3033 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+ ) ;
4351
4452 doc . Add ( root ) ;
4553
@@ -55,13 +63,24 @@ private static IReadOnlyCollection<INavigationItem> GetNavigationItems(IReadOnly
5563 switch ( item )
5664 {
5765 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 ;
5870 result . Add ( file ) ;
5971 break ;
6072 case DocumentationGroup group :
73+ if ( item . Hidden )
74+ continue ;
75+
6176 result . AddRange ( GetNavigationItems ( group . NavigationItems ) ) ;
77+ result . Add ( group ) ;
6278 break ;
79+ default :
80+ throw new Exception ( $ "Unhandled navigation item type: { item . GetType ( ) } ") ;
6381 }
6482 }
83+
6584 return result ;
6685 }
6786}
0 commit comments