-use IkiWiki 2.00;
-
-sub import { #{{{
- hook(type => "needsbuild", id => "recentchanges",
- call => \&needsbuild);
- hook(type => "preprocess", id => "recentchanges",
- call => \&preprocess);
- hook(type => "htmlize", id => "_change",
- call => \&htmlize);
-} #}}}
-
-sub needsbuild ($) { #{{{
- my $needsbuild=shift;
- my @changes=IkiWiki::rcs_recentchanges(100);
- push @$needsbuild, updatechanges("*", "recentchanges", \@changes);
-} #}}}
-
-sub preprocess (@) { #{{{
- my %params=@_;
-
- # TODO
+use IkiWiki 3.00;
+use Encode;
+use HTML::Entities;
+
+sub import {
+ hook(type => "getsetup", id => "recentchanges", call => \&getsetup);
+ hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
+ hook(type => "refresh", id => "recentchanges", call => \&refresh);
+ hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
+ hook(type => "htmlize", id => "_change", call => \&htmlize);
+ # Load goto to fix up links from recentchanges
+ IkiWiki::loadplugin("goto");
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1,
+ },
+ recentchangespage => {
+ type => "string",
+ example => "recentchanges",
+ description => "name of the recentchanges page",
+ safe => 1,
+ rebuild => 1,
+ },
+ recentchangesnum => {
+ type => "integer",
+ example => 100,
+ description => "number of changes to track",
+ safe => 1,
+ rebuild => 0,
+ },
+}
+
+sub checkconfig () {
+ $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
+ $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
+}
+
+sub refresh ($) {
+ my %seen;
+
+ # add new changes
+ foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
+ $seen{store($change, $config{recentchangespage})}=1;
+ }
+
+ # delete old and excess changes
+ foreach my $page (keys %pagesources) {
+ if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) {
+ unlink($config{srcdir}.'/'.$pagesources{$page});
+ }
+ }
+}