sitemap: tool to generate static xml
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 2 May 2017 21:55:49 +0000 (23:55 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 29 May 2017 17:23:12 +0000 (19:23 +0200)
Effectively the same results but easier to maintain.

.gitignore
Makefile
sitemap.xml [deleted file]
tools/mksitemap [new file with mode: 0755]

index 89c1555..bec2de1 100644 (file)
@@ -1,5 +1,8 @@
 # downloaded data and generated includes
 /data
 
+# derived contents
+/sitemap.xml
+
 # site owner tag for google webmaster tools
 /google????????????????.html
index 0c50b05..8e644e8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,12 @@
-all: data/digraphs.inc.pl data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl
+all: sitemap.xml data/digraphs.inc.pl data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl
 more: all data/digraphs-xorg.inc.pl
 
 download: data/DerivedAge.txt data/rfc1345.txt data/xorg-compose data/countryInfo.txt data/browser/caniuse data/browser/usage-wm.tsv data/xcolors
 .PHONY: download
 
+sitemap.xml: tools/mksitemap
+       $< >$@
+
 data/DerivedAge.txt:
        tools/wget-ifmodified http://www.unicode.org/Public/UNIDATA/$(@F) $@
 
diff --git a/sitemap.xml b/sitemap.xml
deleted file mode 100644 (file)
index 2a70777..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
-<url>
-  <loc>http://sheet.shiar.nl/</loc>
-  <changefreq>monthly</changefreq>
-  <priority>1.00</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/readline</loc>
-  <changefreq>yearly</changefreq>
-  <priority>0.80</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/vi</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.80</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/vimperator</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.70</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/mutt</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.70</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/nethack</loc>
-  <changefreq>yearly</changefreq>
-  <priority>0.70</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/mplayer</loc>
-  <changefreq>yearly</changefreq>
-  <priority>0.70</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/digraphs</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.80</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/charset</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.80</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/unicode</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.80</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/source</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.60</priority>
-</url>
-<url>
-  <loc>http://sheet.shiar.nl/writing</loc>
-  <changefreq>monthly</changefreq>
-  <priority>0.75</priority>
-</url>
-</urlset>
diff --git a/tools/mksitemap b/tools/mksitemap
new file mode 100755 (executable)
index 0000000..cbfa8c9
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use 5.014;
+use warnings;
+
+our $VERSION = '1.00';
+
+my @pages = (
+       [''],
+       [qw( readline vi digraphs charset unicode )],
+       [qw( vimperator mutt nethack mplayer )],
+       [qw( writing )],
+       [qw( source )],
+);
+
+my %freq = (
+       (map { $_ => 'yearly' } qw[ readline nethack mplayer ]),
+);
+
+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}) {
+               print '<url>';
+               print "<loc>http://sheet.shiar.nl/$page</loc>";
+               printf '<changefreq>%s</changefreq>', $freq{$page} // 'monthly';
+               printf '<priority>%.2f</priority>', $prio;
+               say '</url>';
+       }
+       $prio -= .1;
+}
+say '</urlset>';
+