summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/recentchanges.pm
blob: fb9841ffdfe00e7c639090713c1c5aa0f15575a3 (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. # Take the first line of the commit message as a summary.
  58. my $m=shift @{$change->{message}};
  59. $change->{summary}=$m->{line};
  60. # See if the committer is an openid.
  61. my $oiduser=IkiWiki::openiduser($change->{user});
  62. if (defined $oiduser) {
  63. $change->{authorurl}=$change->{user};
  64. $change->{user}=$oiduser;
  65. }
  66. elsif (length $config{url}) {
  67. $change->{authorurl}="$config{url}/".
  68. (length $config{userdir} ? "$config{userdir}/" : "").
  69. $change->{user};
  70. }
  71. # Fill out a template with the change info.
  72. my $template=template("change.tmpl", blind_cache => 1);
  73. $template->param(%$change);
  74. $template->param(baseurl => "$config{url}/") if length $config{url};
  75. IkiWiki::run_hooks(pagetemplate => sub {
  76. shift->(page => $page, destpage => $page, template => $template);
  77. });
  78. writefile($page."._change", $config{srcdir}, $template->output);
  79. utime $change->{when}, $change->{when}, "$config{srcdir}/$page._change";
  80. } #}}}
  81. sub updatechanges ($$) { #{{{
  82. my $pagespec=shift;
  83. my $subdir=shift;
  84. my @changes=@{shift()};
  85. foreach my $change (@changes) {
  86. store($change, $subdir);
  87. }
  88. # TODO: delete old
  89. } #}}}
  90. 1