summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 2c20ca195dcd1f55ff4cdbe9ad70fed642c236af (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 => "preprocess", id => "pagecount", call => \&preprocess);
  8. } # }}}
  9. sub preprocess (@) { #{{{
  10. my %params=@_;
  11. $params{pages}="*" unless defined $params{pages};
  12. # Needs to update count whenever a page is added or removed, so
  13. # register a dependency.
  14. add_depends($params{page}, $params{pages});
  15. my @pages=keys %pagesources;
  16. return $#pages+1 if $params{pages} eq "*"; # optimisation
  17. my $count=0;
  18. foreach my $page (@pages) {
  19. $count++ if pagespec_match($page, $params{pages}, location => $params{page});
  20. }
  21. return $count;
  22. } # }}}
  23. 1