summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 7ced159823fff8cf8139392d9b6d81e903f3390f (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});
  21. }
  22. return $count;
  23. } # }}}
  24. 1