]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki-calendar.in
(no commit message)
[ikiwiki.git] / ikiwiki-calendar.in
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;
8
9 sub usage () {
10         die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
11 }
12
13 my $force=0;
14 GetOptions(
15         "force" => \$force,
16 ) || usage();
17 my $setup=shift         || usage();
18 my $pagespec=shift      || "*";
19 my $startyear=shift     || 1900+(localtime(time))[5];
20 my $endyear=shift       || $startyear;
21
22 %config=IkiWiki::defaultconfig();
23 IkiWiki::Setup::load($setup);
24 IkiWiki::loadplugins();
25 IkiWiki::checkconfig();
26
27 my $archivebase = 'archives';
28 $archivebase = $config{archivebase} if defined $config{archivebase};
29
30 sub writearchive ($$;$) {
31         my $template=template(shift);
32         my $year=shift;
33         my $month=shift;
34
35         my $page=defined $month ? "$year/$month" : $year;
36
37         my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
38         $template->param(pagespec => $pagespec);
39         $template->param(year => $year);
40         $template->param(month => $month) if defined $month;
41
42         if ($force || ! -e "$config{srcdir}/$pagefile") {
43                 writefile($pagefile, $config{srcdir}, $template->output);
44                 IkiWiki::rcs_add($pagefile) if $config{rcs};
45         }
46 }
47
48 foreach my $y ($startyear..$endyear) {
49         writearchive("calendaryear.tmpl", $y);
50         foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
51                 writearchive("calendarmonth.tmpl", $y, $m);
52         }
53 }
54
55 IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
56         if $config{rcs};
57
58 system("ikiwiki", "-setup", $setup, "-refresh");