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