Allow dots in parameter key names
[ikiwiki] / IkiWiki / Plugin / transient.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::transient;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "getsetup", id => "transient",  call => \&getsetup);
10         hook(type => "checkconfig", id => "transient", call => \&checkconfig);
11         hook(type => "rendered", id => "transient", call => \&rendered);
12 }
13
14 sub getsetup () {
15         return
16                 plugin => {
17                         # this plugin is safe but only makes sense as a
18                         # dependency; similarly, it needs a rebuild but
19                         # only if something else does
20                         safe => 0,
21                         rebuild => 0,
22                 },
23 }
24
25 our $transientdir;
26
27 sub checkconfig () {
28         if (defined $config{wikistatedir}) {
29                 $transientdir = $config{wikistatedir}."/transient";
30                 # add_underlay treats relative underlays as relative to the installed
31                 # location, not the cwd. That's not what we want here.
32                 IkiWiki::add_literal_underlay($transientdir);
33         }
34 }
35
36 sub rendered (@) {
37         foreach my $file (@_) {
38                 # If the corresponding file exists in the transient underlay
39                 # and isn't actually being used, we can get rid of it.
40                 # Assume that the file that just changed has the same extension
41                 # as the obsolete transient version: this'll be true for web
42                 # edits, and avoids invoking File::Find.
43                 my $casualty = "$transientdir/$file";
44                 if (srcfile($file) ne $casualty && -e $casualty) {
45                         debug(sprintf(gettext("removing transient version of %s"), $file));
46                         IkiWiki::prune($casualty, $transientdir);
47                 }
48         }
49 }
50
51 1;