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