summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 5a2301af49232943d4f0889c0f3b9ba28f05396f (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagecount;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "pagecount", call => \&getsetup);
  8. hook(type => "preprocess", id => "pagecount", call => \&preprocess);
  9. }
  10. sub getsetup () {
  11. return
  12. plugin => {
  13. safe => 1,
  14. rebuild => undef,
  15. },
  16. }
  17. sub preprocess (@) {
  18. my %params=@_;
  19. $params{pages}="*" unless defined $params{pages};
  20. # Needs to update count whenever a page is added or removed, so
  21. # register a dependency.
  22. add_depends($params{page}, $params{pages});
  23. my @pages;
  24. if ($params{pages} eq "*") {
  25. @pages=keys %pagesources;
  26. }
  27. else {
  28. @pages=pagespec_match_list([keys %pagesources], $params{pages}, location => $params{page});
  29. }
  30. return $#pages+1;
  31. }
  32. 1