5 use FindBin; use lib $FindBin::Bin; # For use in nonstandard directory, munged by Makefile.
11 die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [startyear [endyear]]"), "\n";
18 my $setup=shift || usage();
20 if (@ARGV && $ARGV[0] !~ /^\d+$/) {
23 my $startyear=shift || 1900+(localtime(time))[5];
24 my $endyear=shift || $startyear;
26 %config=IkiWiki::defaultconfig();
27 IkiWiki::Setup::load($setup);
28 IkiWiki::loadplugins();
29 IkiWiki::checkconfig();
31 my $archivebase = 'archives';
32 $archivebase = $config{archivebase} if defined $config{archivebase};
34 if (! defined $pagespec) {
35 $pagespec=$config{archive_pagespec} || "*";
38 sub writearchive ($$;$) {
39 my $template=template(shift);
43 my $page=defined $month ? "$year/$month" : $year;
45 my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
46 $template->param(pagespec => $pagespec);
47 $template->param(year => $year);
48 $template->param(month => $month) if defined $month;
50 if ($force || ! -e "$config{srcdir}/$pagefile") {
51 writefile($pagefile, $config{srcdir}, $template->output);
52 IkiWiki::rcs_add($pagefile) if $config{rcs};
56 foreach my $y ($startyear..$endyear) {
57 writearchive("calendaryear.tmpl", $y);
58 foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
59 writearchive("calendarmonth.tmpl", $y, $m);
63 IkiWiki::rcs_commit_staged(message => gettext("calendar update"))
66 exec("ikiwiki", "--setup", $setup, "--refresh");
67 die "failed to run ikiwiki --setup $setup --refresh\n";