]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki-calendar
po: inject custom isselflink to fix selflink detection on translation pages
[ikiwiki.git] / ikiwiki-calendar
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use IkiWiki;
5 use IkiWiki::Setup;
6 use Getopt::Long;
7
8 sub usage () {
9         die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
10 }
11
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;
20
21 %config=IkiWiki::defaultconfig();
22 IkiWiki::Setup::load($setup);
23 IkiWiki::loadplugins();
24 IkiWiki::checkconfig();
25
26 my $archivebase = 'archives';
27 $archivebase = $config{archivebase} if defined $config{archivebase};
28
29 sub writearchive ($$;$) {
30         my $template=template(shift);
31         my $year=shift;
32         my $month=shift;
33
34         my $page=defined $month ? "$year/$month" : $year;
35
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;
40
41         if ($force || ! -e "$config{srcdir}/$pagefile") {
42                 writefile($pagefile, $config{srcdir}, $template->output);
43                 IkiWiki::rcs_add($pagefile) if $config{rcs};
44         }
45 }
46
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);
51         }
52 }
53
54 IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
55         if $config{rcs};
56
57 system("ikiwiki", "-setup", $setup, "-refresh");