]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki-calendar.in
Emit vestigial xmlns so people can still pass ikiwiki output through XSLT
[ikiwiki.git] / ikiwiki-calendar.in
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use lib '.'; # For use in nonstandard directory, munged by Makefile.
5 use IkiWiki;
6 use IkiWiki::Setup;
7 use Getopt::Long;
8
9 sub usage () {
10         die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [startyear [endyear]]"), "\n";
11 }
12
13 my $force=0;
14 GetOptions(
15         "force" => \$force,
16 ) || usage();
17 my $setup=shift         || usage();
18 my $pagespec;
19 if (@ARGV && $ARGV[0] !~ /^\d+$/) {
20         $pagespec=shift;
21 }
22 my $startyear=shift     || 1900+(localtime(time))[5];
23 my $endyear=shift       || $startyear;
24
25 %config=IkiWiki::defaultconfig();
26 IkiWiki::Setup::load($setup);
27 IkiWiki::loadplugins();
28 IkiWiki::checkconfig();
29
30 my $archivebase = 'archives';
31 $archivebase = $config{archivebase} if defined $config{archivebase};
32
33 if (! defined $pagespec) {
34         $pagespec=$config{archive_pagespec} || "*";
35 }
36
37 sub writearchive ($$;$) {
38         my $template=template(shift);
39         my $year=shift;
40         my $month=shift;
41
42         my $page=defined $month ? "$year/$month" : $year;
43
44         my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
45         $template->param(pagespec => $pagespec);
46         $template->param(year => $year);
47         $template->param(month => $month) if defined $month;
48
49         if ($force || ! -e "$config{srcdir}/$pagefile") {
50                 writefile($pagefile, $config{srcdir}, $template->output);
51                 IkiWiki::rcs_add($pagefile) if $config{rcs};
52         }
53 }
54
55 foreach my $y ($startyear..$endyear) {
56         writearchive("calendaryear.tmpl", $y);
57         foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
58                 writearchive("calendarmonth.tmpl", $y, $m);
59         }
60 }
61
62 IkiWiki::rcs_commit_staged(message => gettext("calendar update"))
63         if $config{rcs};
64
65 exec("ikiwiki", "-setup", $setup, "-refresh");
66 die "failed to run ikiwiki -setup $setup -refresh\n";