summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/transient.pm
blob: 2784164f607c2d8210d7a3e88a729ef3f880326c (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::transient;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "transient", call => \&getsetup);
  8. hook(type => "checkconfig", id => "transient", call => \&checkconfig);
  9. hook(type => "change", id => "transient", call => \&change);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. # this plugin is safe but only makes sense as a
  15. # dependency; similarly, it needs a rebuild but
  16. # only if something else does
  17. safe => 0,
  18. rebuild => 0,
  19. },
  20. }
  21. our $transientdir;
  22. sub checkconfig () {
  23. eval q{use Cwd 'abs_path'};
  24. error($@) if $@;
  25. $transientdir = abs_path($config{wikistatedir})."/transient";
  26. add_underlay($transientdir);
  27. }
  28. sub change (@) {
  29. foreach my $file (@_) {
  30. # if the corresponding file exists in the transient underlay
  31. # and isn't actually being used, we can get rid of it
  32. my $page = pagename($file);
  33. my $casualty = "$transientdir/$page.$config{default_pageext}";
  34. if (srcfile($file) ne $casualty && -e $casualty) {
  35. debug(sprintf(gettext("removing transient version of %s"), $page));
  36. IkiWiki::prune($casualty);
  37. }
  38. }
  39. }
  40. 1;