summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: cfc962b6c4df0172fca409033326b3153602fc3f (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::hook(type => "preprocess", id => "pagecount",
  9. call => \&preprocess);
  10. } # }}}
  11. sub preprocess (@) { #{{{
  12. my %params=@_;
  13. $params{pages}="*" unless defined $params{pages};
  14. # Needs to update count whenever a page is added or removed, so
  15. # register a dependency.
  16. IkiWiki::add_depends($params{page}, $params{pages});
  17. my @pages=keys %IkiWiki::pagesources;
  18. return $#pages+1 if $params{pages} eq "*"; # optimisation
  19. my $count=0;
  20. foreach my $page (@pages) {
  21. $count++ if IkiWiki::pagespec_match($page, $params{pages});
  22. }
  23. return $count;
  24. } # }}}
  25. 1