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