summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchanges.pm
blob: 94a2d4c339a8d4e43695f52bf01cb85be8e1c794 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::recentchanges;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import { #{{{
  7. hook(type => "checkconfig", id => "recentchanges",
  8. call => \&checkconfig);
  9. hook(type => "needsbuild", id => "recentchanges",
  10. call => \&needsbuild);
  11. hook(type => "preprocess", id => "recentchanges",
  12. call => \&preprocess);
  13. hook(type => "htmlize", id => "_change",
  14. call => \&htmlize);
  15. } #}}}
  16. sub checkconfig () { #{{{
  17. updatechanges();
  18. } #}}}
  19. sub needsbuild () { #{{{
  20. # TODO
  21. } #}}}
  22. sub preprocess (@) { #{{{
  23. my %params=@_;
  24. # TODO
  25. return "";
  26. } #}}}
  27. # Pages with extension _change have plain html markup, pass through.
  28. sub htmlize (@) { #{{{
  29. my %params=@_;
  30. return $params{content};
  31. } #}}}
  32. sub store ($$) { #{{{
  33. my $change=shift;
  34. my $subdir=shift;
  35. my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
  36. # Optimisation to avoid re-writing pages. Assumes commits never
  37. # change, or that any changes are not important.
  38. return if exists $pagesources{$page} && ! $config{rebuild};
  39. # Limit pages to first 10, and add links to the changed pages.
  40. my $is_excess = exists $change->{pages}[10];
  41. delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
  42. $change->{pages} = [
  43. map {
  44. if (length $config{url}) {
  45. $_->{link} = "<a href=\"$config{url}/".
  46. urlto($_->{page},"")."\">".
  47. IkiWiki::pagetitle($_->{page})."</a>";
  48. }
  49. else {
  50. $_->{link} = IkiWiki::pagetitle($_->{page});
  51. }
  52. $_;
  53. } @{$change->{pages}}
  54. ];
  55. push @{$change->{pages}}, { link => '...' } if $is_excess;
  56. # Fill out a template with the change info.
  57. $change->{user} = IkiWiki::userlink($change->{user});
  58. my $ctime=$change->{when};
  59. $change->{when} = IkiWiki::displaytime($change->{when}, "%X %x");
  60. my $template=template("change.tmpl", blind_cache => 1);
  61. $template->param(%$change);
  62. $template->param(baseurl => "$config{url}/") if length $config{url};
  63. IkiWiki::run_hooks(pagetemplate => sub {
  64. shift->(page => $page, destpage => $page, template => $template);
  65. });
  66. writefile($page."._change", $config{srcdir}, $template->output);
  67. utime $ctime, $ctime, "$config{srcdir}/$page._change";
  68. } #}}}
  69. sub updatechanges () { #{{{
  70. my @changelog=IkiWiki::rcs_recentchanges(100);
  71. foreach my $change (@changelog) {
  72. store($change, "recentchanges");
  73. }
  74. # TODO: delete old
  75. } #}}}
  76. 1