summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
blob: 8d36f057eb0820a62c9704988d66fde75ccf6c4b (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. my $pages=defined $params{pages} ? $params{pages} : "*";
  20. # Just get a list of all the pages, and count the items in it.
  21. # Use a presence dependency to only update when pages are added
  22. # or removed.
  23. if ($pages eq '*') {
  24. # optimisation to avoid needing to try matching every page
  25. add_depends($params{page}, $pages, deptype("presence"));
  26. return scalar keys %pagesources;
  27. }
  28. return scalar pagespec_match_list($params{page}, $pages,
  29. deptype => deptype("presence"));
  30. }
  31. 1