2 package IkiWiki::Plugin::recentchanges;
9 hook(type => "checkconfig", id => "recentchanges",
10 call => \&checkconfig);
11 hook(type => "needsbuild", id => "recentchanges",
12 call => \&needsbuild);
13 hook(type => "preprocess", id => "recentchanges",
14 call => \&preprocess);
15 hook(type => "htmlize", id => "_change",
19 sub checkconfig () { #{{{
20 my @changes=IkiWiki::rcs_recentchanges(100);
21 updatechanges("*", "recentchanges", \@changes);
24 sub needsbuild () { #{{{
28 sub preprocess (@) { #{{{
36 # Pages with extension _change have plain html markup, pass through.
37 sub htmlize (@) { #{{{
39 return $params{content};
46 my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
48 # Optimisation to avoid re-writing pages. Assumes commits never
49 # change (or that any changes are not important).
50 return if exists $pagesources{$page} && ! $config{rebuild};
52 # Limit pages to first 10, and add links to the changed pages.
53 my $is_excess = exists $change->{pages}[10];
54 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
57 if (length $config{url}) {
58 $_->{link} = "<a href=\"$config{url}/".
59 urlto($_->{page},"")."\">".
60 IkiWiki::pagetitle($_->{page})."</a>";
63 $_->{link} = IkiWiki::pagetitle($_->{page});
68 push @{$change->{pages}}, { link => '...' } if $is_excess;
70 # Fill out a template with the change info.
71 my $template=template("change.tmpl", blind_cache => 1);
73 user => IkiWiki::userlink($change->{user}),
74 when => IkiWiki::displaytime($change->{when}, "%X %x"),
75 pages => $change->{pages},
76 message => $change->{message},
78 $template->param(baseurl => "$config{url}/") if length $config{url};
79 IkiWiki::run_hooks(pagetemplate => sub {
80 shift->(page => $page, destpage => $page, template => $template);
83 writefile($page."._change", $config{srcdir}, $template->output);
84 utime $change->{when}, $change->{when}, "$config{srcdir}/$page._change";
87 sub updatechanges ($$) { #{{{
90 my @changes=@{shift()};
91 foreach my $change (@changes) {
92 store($change, $subdir);