summaryrefslogtreecommitdiff
path: root/ikiwiki-calendar.in
blob: cdfecff3f3a41e2c5c2ff3d2ef9230eb1453d6df (plain)
  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;
  8. sub usage () {
  9. die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
  10. }
  11. my $force=0;
  12. GetOptions(
  13. "force" => \$force,
  14. ) || usage();
  15. my $setup=shift || usage();
  16. my $pagespec=shift;
  17. my $startyear=shift || 1900+(localtime(time))[5];
  18. my $endyear=shift || $startyear;
  19. %config=IkiWiki::defaultconfig();
  20. IkiWiki::Setup::load($setup);
  21. IkiWiki::loadplugins();
  22. IkiWiki::checkconfig();
  23. my $archivebase = 'archives';
  24. $archivebase = $config{archivebase} if defined $config{archivebase};
  25. if (! defined $pagespec) {
  26. $pagespec=$config{archive_pagespec} || "*";
  27. }
  28. sub writearchive ($$;$) {
  29. my $template=template(shift);
  30. my $year=shift;
  31. my $month=shift;
  32. my $page=defined $month ? "$year/$month" : $year;
  33. my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
  34. $template->param(pagespec => $pagespec);
  35. $template->param(year => $year);
  36. $template->param(month => $month) if defined $month;
  37. if ($force || ! -e "$config{srcdir}/$pagefile") {
  38. writefile($pagefile, $config{srcdir}, $template->output);
  39. IkiWiki::rcs_add($pagefile) if $config{rcs};
  40. }
  41. }
  42. foreach my $y ($startyear..$endyear) {
  43. writearchive("calendaryear.tmpl", $y);
  44. foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
  45. writearchive("calendarmonth.tmpl", $y, $m);
  46. }
  47. }
  48. IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
  49. if $config{rcs};
  50. exec("ikiwiki", "-setup", $setup, "-refresh");
  51. die "failed to run ikiwiki -setup $setup -refresh\n";