aboutsummaryrefslogtreecommitdiff
path: root/ikiwiki-calendar
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-10-11 16:42:49 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-10-11 16:52:54 -0400
commite1939185d29e1431861e63d6526cb3a498d6033e (patch)
treef275b46d51d4fcc1e8faf8916e7c7f2069858107 /ikiwiki-calendar
parent5cddd8a0a3b1b42dd3a92eb4f839679c12ddf97e (diff)
downloadikiwiki-e1939185d29e1431861e63d6526cb3a498d6033e.tar
ikiwiki-e1939185d29e1431861e63d6526cb3a498d6033e.tar.gz
ikiwiki-calendar: New command automates creation of archive pages using the calendar plugin.
Diffstat (limited to 'ikiwiki-calendar')
-rwxr-xr-xikiwiki-calendar59
1 files changed, 59 insertions, 0 deletions
diff --git a/ikiwiki-calendar b/ikiwiki-calendar
new file mode 100755
index 000000000..ec572cb7c
--- /dev/null
+++ b/ikiwiki-calendar
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use IkiWiki;
+use IkiWiki::Setup;
+use Getopt::Long;
+
+sub usage () {
+ die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
+}
+
+my $force=0;
+GetOptions(
+ "force" => \$force,
+) || usage();
+my $setup=shift || usage();
+my $pagespec=shift || "*";
+my $year=shift || 1900+(localtime(time))[5];
+
+%config=IkiWiki::defaultconfig();
+IkiWiki::Setup::load($setup);
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+
+my $archivebase = 'archives';
+$archivebase = $config{archivebase} if defined $config{archivebase};
+
+sub writearchive ($$;$) {
+ my $template=template(shift);
+ my $year=shift;
+ my $month=shift;
+
+ my $page=defined $month ? "$year/$month" : $year;
+
+ my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
+ $template->param(pagespec => $pagespec);
+ $template->param(year => $year);
+ $template->param(month => $month) if defined $month;
+
+ if ($force || ! -e "$config{srcdir}/$pagefile") {
+ writefile($pagefile, $config{srcdir}, $template->output);
+ IkiWiki::rcs_add($pagefile) if $config{rcs};
+ }
+}
+
+IkiWiki::lockwiki();
+
+foreach my $y ($year-1, $year, $year+1) {
+ writearchive("calendaryear.tmpl", $y);
+ foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
+ writearchive("calendarmonth.tmpl", $y, $m);
+ }
+}
+
+IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
+ if $config{rcs};
+IkiWiki::unlockwiki();
+
+system("ikiwiki", "-setup", $setup, "-refresh");