summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 5ba7ee50b0bd61df0f9c75ea44761795cb65749a (plain)
  1. #!/usr/bin/perl
  2. # Provides [[pagecount ]] to count the number of pages.
  3. package IkiWiki::Plugin::pagecount;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. sub import { #{{{
  8. hook(type => "preprocess", id => "pagecount", call => \&preprocess);
  9. } # }}}
  10. sub preprocess (@) { #{{{
  11. my %params=@_;
  12. $params{pages}="*" unless defined $params{pages};
  13. # Needs to update count whenever a page is added or removed, so
  14. # register a dependency.
  15. add_depends($params{page}, $params{pages});
  16. my @pages=keys %pagesources;
  17. return $#pages+1 if $params{pages} eq "*"; # optimisation
  18. my $count=0;
  19. foreach my $page (@pages) {
  20. $count++ if pagespec_match($page, $params{pages}, $params{page});
  21. }
  22. return $count;
  23. } # }}}
  24. 1