add news item for ikiwiki 3.20110124
[ikiwiki.git] / ikiwiki-calendar.in
blob60df99855df63a8a248b78616911359035477a1a
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;
9 sub usage () {
10 die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
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;
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);
39 my $year=shift;
40 my $month=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"))
63 if $config{rcs};
65 exec("ikiwiki", "-setup", $setup, "-refresh");
66 die "failed to run ikiwiki -setup $setup -refresh\n";