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