summaryrefslogtreecommitdiff
path: root/ikiwiki-calendar
blob: a9548d6ec63813d2c150938f1df82ae5da2d6b4a (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 $startyear=shift || 1900+(localtime(time))[5];
  17. my $endyear=shift || $startyear;
  18. %config=IkiWiki::defaultconfig();
  19. IkiWiki::Setup::load($setup);
  20. IkiWiki::loadplugins();
  21. IkiWiki::checkconfig();
  22. my $archivebase = 'archives';
  23. $archivebase = $config{archivebase} if defined $config{archivebase};
  24. sub writearchive ($$;$) {
  25. my $template=template(shift);
  26. my $year=shift;
  27. my $month=shift;
  28. my $page=defined $month ? "$year/$month" : $year;
  29. my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
  30. $template->param(pagespec => $pagespec);
  31. $template->param(year => $year);
  32. $template->param(month => $month) if defined $month;
  33. if ($force || ! -e "$config{srcdir}/$pagefile") {
  34. writefile($pagefile, $config{srcdir}, $template->output);
  35. IkiWiki::rcs_add($pagefile) if $config{rcs};
  36. }
  37. }
  38. foreach my $y ($startyear..$endyear) {
  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. system("ikiwiki", "-setup", $setup, "-refresh");