summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: fc69e449bb2612ee6afb73f95b4d9977448afbb5 (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. IkiWiki::register_plugin("preprocess", "pagecount", \&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. IkiWiki::add_depends($params{page}, $params{pages});
  16. my @pages=keys %IkiWiki::pagesources;
  17. return $#pages+1 if $params{pages} eq "*"; # optimisation
  18. my $count=0;
  19. foreach my $page (@pages) {
  20. $count++ if IkiWiki::globlist_match($page, $params{pages});
  21. }
  22. return $count;
  23. } # }}}
  24. 1