sitemap: include file dates in lastmod attribute
[sheet.git] / tools / mksitemap
index cbfa8c93c7c14b450100401d97f5fe2eeefe5377..7b9c5a01016e530108d9a7822f3a1b8e87c41c7f 100755 (executable)
@@ -4,8 +4,11 @@ use warnings;
 
 our $VERSION = '1.00';
 
+use File::stat;
+use Time::Piece;
+
 my @pages = (
-       [''],
+       [qw( index )],
        [qw( readline vi digraphs charset unicode )],
        [qw( vimperator mutt nethack mplayer )],
        [qw( writing )],
@@ -16,15 +19,22 @@ my %freq = (
        (map { $_ => 'yearly' } qw[ readline nethack mplayer ]),
 );
 
+my %known = map { $_ => 1 } map { @{$_} } @pages;
+$known{$_} or warn "page $_ undeclared\n"
+       for grep { !/\./ } map { s/\.plp\z//r } glob '*.plp';
+
 say '<?xml version="1.0" encoding="UTF-8"?>';
 say '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
 for my $group (@pages) {
        state $prio = 1;
-       for my $page (@{$group}) {
+       for my $file (@{$group}) {
+               (my $page = $file) =~ s/\Aindex\z//;
+               $file .= '.plp';
                print '<url>';
                print "<loc>http://sheet.shiar.nl/$page</loc>";
                printf '<changefreq>%s</changefreq>', $freq{$page} // 'monthly';
                printf '<priority>%.2f</priority>', $prio;
+               printf '<lastmod>%s</lastmod>', localtime(stat($file)->mtime)->date;
                say '</url>';
        }
        $prio -= .1;