ikiwiki/ikiwiki-calendar.in

63 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
use warnings;
use strict;
use lib '.'; # For use in nonstandard directory, munged by Makefile.
use IkiWiki;
use IkiWiki::Setup;
use Getopt::Long;
sub usage () {
die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
}
my $force=0;
GetOptions(
"force" => \$force,
) || usage();
my $setup=shift || usage();
my $pagespec=shift;
2009-10-12 05:44:50 +02:00
my $startyear=shift || 1900+(localtime(time))[5];
my $endyear=shift || $startyear;
%config=IkiWiki::defaultconfig();
IkiWiki::Setup::load($setup);
IkiWiki::loadplugins();
IkiWiki::checkconfig();
my $archivebase = 'archives';
$archivebase = $config{archivebase} if defined $config{archivebase};
if (! defined $pagespec) {
$pagespec=$config{archive_pagespec} || "*";
}
sub writearchive ($$;$) {
my $template=template(shift);
my $year=shift;
my $month=shift;
my $page=defined $month ? "$year/$month" : $year;
my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
$template->param(pagespec => $pagespec);
$template->param(year => $year);
$template->param(month => $month) if defined $month;
if ($force || ! -e "$config{srcdir}/$pagefile") {
writefile($pagefile, $config{srcdir}, $template->output);
IkiWiki::rcs_add($pagefile) if $config{rcs};
}
}
2009-10-12 05:44:50 +02:00
foreach my $y ($startyear..$endyear) {
writearchive("calendaryear.tmpl", $y);
foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
writearchive("calendarmonth.tmpl", $y, $m);
}
}
IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
if $config{rcs};
system("ikiwiki", "-setup", $setup, "-refresh");