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 () { #{{{
23 sub needsbuild () { #{{{
27 sub preprocess (@) { #{{{
35 # Pages with extension _change have plain html markup, pass through.
36 sub htmlize (@) { #{{{
38 return $params{content};
45 my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
47 # Optimisation to avoid re-writing pages. Assumes commits never
48 # change, or that any changes are not important.
49 return if exists $pagesources{$page} && ! $config{rebuild};
51 # Limit pages to first 10, and add links to the changed pages.
52 my $is_excess = exists $change->{pages}[10];
53 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
56 if (length $config{url}) {
57 $_->{link} = "<a href=\"$config{url}/".
58 urlto($_->{page},"")."\">".
59 IkiWiki::pagetitle($_->{page})."</a>";
62 $_->{link} = IkiWiki::pagetitle($_->{page});
67 push @{$change->{pages}}, { link => '...' } if $is_excess;
69 # Fill out a template with the change info.
70 $change->{user} = IkiWiki::userlink($change->{user});
71 my $ctime=$change->{when};
72 $change->{when} = IkiWiki::displaytime($change->{when}, "%X %x");
73 my $template=template("change.tmpl", blind_cache => 1);
74 $template->param(%$change);
75 $template->param(baseurl => "$config{url}/") if length $config{url};
76 IkiWiki::run_hooks(pagetemplate => sub {
77 shift->(page => $page, destpage => $page, template => $template);
80 writefile($page."._change", $config{srcdir}, $template->output);
81 utime $ctime, $ctime, "$config{srcdir}/$page._change";
84 sub updatechanges () { #{{{
85 my @changelog=IkiWiki::rcs_recentchanges(100);
86 foreach my $change (@changelog) {
87 store($change, "recentchanges");