summaryrefslogtreecommitdiff
path: root/ikiwiki-calendar.in
blob: 9738ea5f7195cef46bf6480fc5c515fd89438cbe (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. sub writearchive ($$;$) {
  26. my $template=template(shift);
  27. my $year=shift;
  28. my $month=shift;
  29. my $page=defined $month ? "$year/$month" : $year;
  30. my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
  31. $template->param(pagespec => $pagespec);
  32. $template->param(year => $year);
  33. $template->param(month => $month) if defined $month;
  34. if ($force || ! -e "$config{srcdir}/$pagefile") {
  35. writefile($pagefile, $config{srcdir}, $template->output);
  36. IkiWiki::rcs_add($pagefile) if $config{rcs};
  37. }
  38. }
  39. foreach my $y ($startyear..$endyear) {
  40. writearchive("calendaryear.tmpl", $y);
  41. foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
  42. writearchive("calendarmonth.tmpl", $y, $m);
  43. }
  44. }
  45. IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
  46. if $config{rcs};
  47. system("ikiwiki", "-setup", $setup, "-refresh");