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