]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki-calendar.in
follow-up: sorry, I appreciate that wasn't as useful as it could have been
[git.ikiwiki.info.git] / ikiwiki-calendar.in
1 #!/usr/bin/perl
2 no lib '.';
3 use warnings;
4 use strict;
5 use FindBin; use lib $FindBin::Bin; # For use in nonstandard directory, munged by Makefile.
6 use IkiWiki;
7 use IkiWiki::Setup;
8 use Getopt::Long;
10 sub usage () {
11         die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [startyear [endyear]]"), "\n";
12 }
14 my $force=0;
15 GetOptions(
16         "force" => \$force,
17 ) || usage();
18 my $setup=shift         || usage();
19 my $pagespec;
20 if (@ARGV && $ARGV[0] !~ /^\d+$/) {
21         $pagespec=shift;
22 }
23 my $startyear=shift     || 1900+(localtime(time))[5];
24 my $endyear=shift       || $startyear;
26 %config=IkiWiki::defaultconfig();
27 IkiWiki::Setup::load($setup);
28 IkiWiki::loadplugins();
29 IkiWiki::checkconfig();
31 my $archivebase = 'archives';
32 $archivebase = $config{archivebase} if defined $config{archivebase};
34 if (! defined $pagespec) {
35         $pagespec=$config{archive_pagespec} || "*";
36 }
38 sub writearchive ($$;$) {
39         my $template=template(shift);
40         my $year=shift;
41         my $month=shift;
43         my $page=defined $month ? "$year/$month" : $year;
45         my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
46         $template->param(pagespec => $pagespec);
47         $template->param(year => $year);
48         $template->param(month => $month) if defined $month;
50         if ($force || ! -e "$config{srcdir}/$pagefile") {
51                 writefile($pagefile, $config{srcdir}, $template->output);
52                 IkiWiki::rcs_add($pagefile) if $config{rcs};
53         }
54 }
56 foreach my $y ($startyear..$endyear) {
57         writearchive("calendaryear.tmpl", $y);
58         foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
59                 writearchive("calendarmonth.tmpl", $y, $m);
60         }
61 }
63 IkiWiki::rcs_commit_staged(message => gettext("calendar update"))
64         if $config{rcs};
66 exec("ikiwiki", "--setup", $setup, "--refresh");
67 die "failed to run ikiwiki --setup $setup --refresh\n";