4 use lib '.'; # For use in nonstandard directory, munged by Makefile.
10 die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
17 my $setup=shift || usage();
19 if (@ARGV && $ARGV[0] !~ /^\d+$/) {
22 my $startyear=shift || 1900+(localtime(time))[5];
23 my $endyear=shift || $startyear;
25 %config=IkiWiki::defaultconfig();
26 IkiWiki::Setup::load($setup);
27 IkiWiki::loadplugins();
28 IkiWiki::checkconfig();
30 my $archivebase = 'archives';
31 $archivebase = $config{archivebase} if defined $config{archivebase};
33 if (! defined $pagespec) {
34 $pagespec=$config{archive_pagespec} || "*";
37 sub writearchive ($$;$) {
38 my $template=template(shift);
42 my $page=defined $month ? "$year/$month" : $year;
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;
49 if ($force || ! -e "$config{srcdir}/$pagefile") {
50 writefile($pagefile, $config{srcdir}, $template->output);
51 IkiWiki::rcs_add($pagefile) if $config{rcs};
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);
62 IkiWiki::rcs_commit_staged(message => gettext("calendar update"))
65 exec("ikiwiki", "-setup", $setup, "-refresh");
66 die "failed to run ikiwiki -setup $setup -refresh\n";