88
99namespace Documentation . Assembler . Building ;
1010
11- public class SitemapBuilder ( IReadOnlyCollection < INavigationItem > navigationItems , IFileSystem fileSystem , IDirectoryInfo outputFolder )
11+ public class SitemapBuilder (
12+ IReadOnlyCollection < INavigationItem > navigationItems ,
13+ IFileSystem fileSystem ,
14+ IDirectoryInfo outputFolder
15+ )
1216{
1317 private static readonly Uri BaseUri = new ( "https://www.elastic.co" ) ;
14- private readonly IReadOnlyCollection < INavigationItem > _navigationItems = navigationItems ;
15- private readonly IFileSystem _fileSystem = fileSystem ;
16- private readonly IDirectoryInfo _outputFolder = outputFolder ;
1718
1819 public void Generate ( )
1920 {
20- var flattenedNavigationItems = GetNavigationItems ( _navigationItems ) ;
21+ var flattenedNavigationItems = GetNavigationItems ( navigationItems ) ;
2122
2223 var doc = new XDocument ( )
2324 {
2425 Declaration = new XDeclaration ( "1.0" , "utf-8" , "yes" ) ,
2526 } ;
2627
28+ var currentDate = DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:sszzz" ) ;
2729 var root = new XElement (
2830 "urlset" ,
2931 new XAttribute ( "xlmns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ,
@@ -32,12 +34,15 @@ public void Generate()
3234 . Select ( n => n . File . Url )
3335 . Distinct ( )
3436 . Select ( u => new Uri ( BaseUri , u ) )
35- . Select ( u => new XElement ( "url" , new XElement ( "loc" , u ) ) )
37+ . Select ( u => new XElement ( "url" , [
38+ new XElement ( "loc" , u ) ,
39+ new XElement ( "lastmod" , currentDate )
40+ ] ) )
3641 ) ;
3742
3843 doc . Add ( root ) ;
3944
40- using var fileStream = _fileSystem . File . Create ( Path . Combine ( _outputFolder . ToString ( ) ?? string . Empty , "docs" , "sitemap.xml" ) ) ;
45+ using var fileStream = fileSystem . File . Create ( Path . Combine ( outputFolder . ToString ( ) ?? string . Empty , "docs" , "sitemap.xml" ) ) ;
4146 doc . Save ( fileStream ) ;
4247 }
4348
@@ -54,6 +59,9 @@ private static IReadOnlyCollection<INavigationItem> GetNavigationItems(IReadOnly
5459 case GroupNavigationItem group :
5560 result . AddRange ( GetNavigationItems ( group . Group . NavigationItems ) ) ;
5661 break ;
62+ case DocumentationGroup group :
63+ result . AddRange ( GetNavigationItems ( group . NavigationItems ) ) ;
64+ break ;
5765 }
5866 }
5967 return result ;
0 commit comments