summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: c08ab3931df261de093a558002712a4ccc5db685 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagecount;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.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=keys %pagesources;
  24. return $#pages+1 if $params{pages} eq "*"; # optimisation
  25. my $count=0;
  26. foreach my $page (@pages) {
  27. $count++ if pagespec_match($page, $params{pages}, location => $params{page});
  28. }
  29. return $count;
  30. }
  31. 1