sort-order could usefully be overridden for meta author, too
[ikiwiki.git] / ikiwiki-calendar.in
blob9738ea5f7195cef46bf6480fc5c515fd89438cbe
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=shift || "*";
19 my $startyear=shift || 1900+(localtime(time))[5];
20 my $endyear=shift || $startyear;
22 %config=IkiWiki::defaultconfig();
23 IkiWiki::Setup::load($setup);
24 IkiWiki::loadplugins();
25 IkiWiki::checkconfig();
27 my $archivebase = 'archives';
28 $archivebase = $config{archivebase} if defined $config{archivebase};
30 sub writearchive ($$;$) {
31 my $template=template(shift);
32 my $year=shift;
33 my $month=shift;
35 my $page=defined $month ? "$year/$month" : $year;
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;
42 if ($force || ! -e "$config{srcdir}/$pagefile") {
43 writefile($pagefile, $config{srcdir}, $template->output);
44 IkiWiki::rcs_add($pagefile) if $config{rcs};
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);
55 IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
56 if $config{rcs};
58 system("ikiwiki", "-setup", $setup, "-refresh");