summaryrefslogtreecommitdiff
path: root/ikiwiki-calendar
blob: ec572cb7ce3373244188602b01f80a57b63ec053 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use IkiWiki;
  5. use IkiWiki::Setup;
  6. use Getopt::Long;
  7. sub usage () {
  8. die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
  9. }
  10. my $force=0;
  11. GetOptions(
  12. "force" => \$force,
  13. ) || usage();
  14. my $setup=shift || usage();
  15. my $pagespec=shift || "*";
  16. my $year=shift || 1900+(localtime(time))[5];
  17. %config=IkiWiki::defaultconfig();
  18. IkiWiki::Setup::load($setup);
  19. IkiWiki::loadplugins();
  20. IkiWiki::checkconfig();
  21. my $archivebase = 'archives';
  22. $archivebase = $config{archivebase} if defined $config{archivebase};
  23. sub writearchive ($$;$) {
  24. my $template=template(shift);
  25. my $year=shift;
  26. my $month=shift;
  27. my $page=defined $month ? "$year/$month" : $year;
  28. my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
  29. $template->param(pagespec => $pagespec);
  30. $template->param(year => $year);
  31. $template->param(month => $month) if defined $month;
  32. if ($force || ! -e "$config{srcdir}/$pagefile") {
  33. writefile($pagefile, $config{srcdir}, $template->output);
  34. IkiWiki::rcs_add($pagefile) if $config{rcs};
  35. }
  36. }
  37. IkiWiki::lockwiki();
  38. foreach my $y ($year-1, $year, $year+1) {
  39. writearchive("calendaryear.tmpl", $y);
  40. foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
  41. writearchive("calendarmonth.tmpl", $y, $m);
  42. }
  43. }
  44. IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
  45. if $config{rcs};
  46. IkiWiki::unlockwiki();
  47. system("ikiwiki", "-setup", $setup, "-refresh");