aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/version.pm
blob: fc265526c15e41682efec8c7702d3a54e5efcf17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
# Ikiwiki version plugin.
package IkiWiki::Plugin::version;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type => "getsetup", id => "version", call => \&getsetup);
	hook(type => "needsbuild", id => "version", call => \&needsbuild);
	hook(type => "preprocess", id => "version", call => \&preprocess);
}

sub getsetup () {
	return
		plugin => {
			safe => 1,
			rebuild => undef,
			section => "widget",
		},
}

sub needsbuild (@) {
	my $needsbuild=shift;
	foreach my $page (keys %pagestate) {
		if (exists $pagestate{$page}{version}{shown}) {
			if ($pagestate{$page}{version}{shown} ne $IkiWiki::version) {
				push @$needsbuild, $pagesources{$page};
			}
			if (exists $pagesources{$page} &&
			    grep { $_ eq $pagesources{$page} } @$needsbuild) {
				# remove state, will be re-added if
				# the version is still shown during the
				# rebuild
				delete $pagestate{$page}{version}{shown};
			}
		}
	}
	return $needsbuild;
}

sub preprocess (@) {
	my %params=@_;
	$pagestate{$params{destpage}}{version}{shown}=$IkiWiki::version;
}

1