summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/version.pm
blob: 3526dafde5bb4df0403aebda6c9bca5e3aadb86e (plain)
  1. #!/usr/bin/perl
  2. # Ikiwiki version plugin.
  3. package IkiWiki::Plugin::version;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. sub import {
  8. hook(type => "getsetup", id => "version", call => \&getsetup);
  9. hook(type => "needsbuild", id => "version", call => \&needsbuild);
  10. hook(type => "preprocess", id => "version", call => \&preprocess);
  11. }
  12. sub getsetup () {
  13. return
  14. plugin => {
  15. safe => 1,
  16. rebuild => undef,
  17. },
  18. }
  19. sub needsbuild (@) {
  20. my $needsbuild=shift;
  21. foreach my $page (keys %pagestate) {
  22. if (exists $pagestate{$page}{version}{shown}) {
  23. if ($pagestate{$page}{version}{shown} ne $IkiWiki::version) {
  24. push @$needsbuild, $pagesources{$page};
  25. }
  26. if (exists $pagesources{$page} &&
  27. grep { $_ eq $pagesources{$page} } @$needsbuild) {
  28. # remove state, will be re-added if
  29. # the version is still shown during the
  30. # rebuild
  31. delete $pagestate{$page}{version}{shown};
  32. }
  33. }
  34. }
  35. }
  36. sub preprocess (@) {
  37. my %params=@_;
  38. $pagestate{$params{destpage}}{version}{shown}=$IkiWiki::version;
  39. }
  40. 1