doc/bugs/img_vs_align: New.
[ikiwiki.git] / ikiwiki-calendar
bloba9548d6ec63813d2c150938f1df82ae5da2d6b4a
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use IkiWiki;
5 use IkiWiki::Setup;
6 use Getopt::Long;
8 sub usage () {
9 die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
12 my $force=0;
13 GetOptions(
14 "force" => \$force,
15 ) || usage();
16 my $setup=shift || usage();
17 my $pagespec=shift || "*";
18 my $startyear=shift || 1900+(localtime(time))[5];
19 my $endyear=shift || $startyear;
21 %config=IkiWiki::defaultconfig();
22 IkiWiki::Setup::load($setup);
23 IkiWiki::loadplugins();
24 IkiWiki::checkconfig();
26 my $archivebase = 'archives';
27 $archivebase = $config{archivebase} if defined $config{archivebase};
29 sub writearchive ($$;$) {
30 my $template=template(shift);
31 my $year=shift;
32 my $month=shift;
34 my $page=defined $month ? "$year/$month" : $year;
36 my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
37 $template->param(pagespec => $pagespec);
38 $template->param(year => $year);
39 $template->param(month => $month) if defined $month;
41 if ($force || ! -e "$config{srcdir}/$pagefile") {
42 writefile($pagefile, $config{srcdir}, $template->output);
43 IkiWiki::rcs_add($pagefile) if $config{rcs};
47 foreach my $y ($startyear..$endyear) {
48 writearchive("calendaryear.tmpl", $y);
49 foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
50 writearchive("calendarmonth.tmpl", $y, $m);
54 IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
55 if $config{rcs};
57 system("ikiwiki", "-setup", $setup, "-refresh");