2009-10-11 22:42:49 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2010-03-26 18:11:02 +01:00
|
|
|
use lib '.'; # For use in nonstandard directory, munged by Makefile.
|
2009-10-11 22:42:49 +02:00
|
|
|
use IkiWiki;
|
|
|
|
use IkiWiki::Setup;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
sub usage () {
|
2011-06-13 18:20:21 +02:00
|
|
|
die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [startyear [endyear]]"), "\n";
|
2009-10-11 22:42:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $force=0;
|
|
|
|
GetOptions(
|
|
|
|
"force" => \$force,
|
|
|
|
) || usage();
|
|
|
|
my $setup=shift || usage();
|
2010-04-16 00:51:35 +02:00
|
|
|
my $pagespec;
|
|
|
|
if (@ARGV && $ARGV[0] !~ /^\d+$/) {
|
|
|
|
$pagespec=shift;
|
|
|
|
}
|
2009-10-12 05:44:50 +02:00
|
|
|
my $startyear=shift || 1900+(localtime(time))[5];
|
|
|
|
my $endyear=shift || $startyear;
|
2009-10-11 22:42:49 +02:00
|
|
|
|
|
|
|
%config=IkiWiki::defaultconfig();
|
|
|
|
IkiWiki::Setup::load($setup);
|
|
|
|
IkiWiki::loadplugins();
|
|
|
|
IkiWiki::checkconfig();
|
|
|
|
|
|
|
|
my $archivebase = 'archives';
|
|
|
|
$archivebase = $config{archivebase} if defined $config{archivebase};
|
|
|
|
|
2010-04-15 19:40:53 +02:00
|
|
|
if (! defined $pagespec) {
|
|
|
|
$pagespec=$config{archive_pagespec} || "*";
|
|
|
|
}
|
|
|
|
|
2009-10-11 22:42:49 +02:00
|
|
|
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) {
|
2009-10-11 22:42:49 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:35:21 +02:00
|
|
|
IkiWiki::rcs_commit_staged(message => gettext("calendar update"))
|
2009-10-11 22:42:49 +02:00
|
|
|
if $config{rcs};
|
|
|
|
|
2015-03-01 17:14:32 +01:00
|
|
|
exec("ikiwiki", "--setup", $setup, "--refresh");
|
|
|
|
die "failed to run ikiwiki --setup $setup --refresh\n";
|