2 package IkiWiki::Plugin::recentchanges;
9 hook(type => "needsbuild", id => "recentchanges",
10 call => \&needsbuild);
11 hook(type => "preprocess", id => "recentchanges",
12 call => \&preprocess);
13 hook(type => "htmlize", id => "_change",
17 sub needsbuild () { #{{{
18 my @changes=IkiWiki::rcs_recentchanges(100);
19 updatechanges("*", "recentchanges", \@changes);
22 sub preprocess (@) { #{{{
30 # Pages with extension _change have plain html markup, pass through.
31 sub htmlize (@) { #{{{
33 return $params{content};
40 my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
42 # Optimisation to avoid re-writing pages. Assumes commits never
43 # change (or that any changes are not important).
44 return if exists $pagesources{$page} && ! $config{rebuild};
46 # Limit pages to first 10, and add links to the changed pages.
47 my $is_excess = exists $change->{pages}[10];
48 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
51 if (length $config{url}) {
52 $_->{link} = "<a href=\"$config{url}/".
53 urlto($_->{page},"")."\">".
54 IkiWiki::pagetitle($_->{page})."</a>";
57 $_->{link} = IkiWiki::pagetitle($_->{page});
62 push @{$change->{pages}}, { link => '...' } if $is_excess;
64 # Take the first line of the commit message as a summary.
65 #my $m=shift @{$change->{message}};
66 #$change->{summary}=$m->{line};
67 #delete $change->{message} unless @{$change->{message}};
69 # See if the committer is an openid.
70 my $oiduser=IkiWiki::openiduser($change->{user});
71 if (defined $oiduser) {
72 $change->{authorurl}=$change->{user};
73 $change->{user}=$oiduser;
75 elsif (length $config{url}) {
76 $change->{authorurl}="$config{url}/".
77 (length $config{userdir} ? "$config{userdir}/" : "").
81 # Fill out a template with the change info.
82 my $template=template("change.tmpl", blind_cache => 1);
85 commitdate => displaytime($change->{when}, "%X %x"),
86 wikiname => $config{wikiname},
88 $template->param(baseurl => "$config{url}/") if length $config{url};
89 IkiWiki::run_hooks(pagetemplate => sub {
90 shift->(page => $page, destpage => $page, template => $template);
93 my $html=$template->output;
94 # escape wikilinks and preprocessor stuff
95 $html=~s/(?<!\\)\[\[/\\\[\[/g;
96 writefile($page."._change", $config{srcdir}, $html);
97 utime $change->{when}, $change->{when}, "$config{srcdir}/$page._change";
100 sub updatechanges ($$) { #{{{
103 my @changes=@{shift()};
104 foreach my $change (@changes) {
105 store($change, $subdir);