summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 313ffdff0d6e9c225957d692fbfdea6a9f3109a3 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagecount;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  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}, $params{page});
  20. }
  21. return $count;
  22. } # }}}
  23. 1