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