]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/pagecount.pm
aggregrate: Fix several bugs in handling of empty and colliding titles when generatin...
[git.ikiwiki.info.git] / IkiWiki / Plugin / pagecount.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::pagecount;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9         hook(type => "getsetup", id => "pagecount", call => \&getsetup);
10         hook(type => "preprocess", id => "pagecount", call => \&preprocess);
11 }
13 sub getsetup () {
14         return 
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                         section => "widget",
19                 },
20 }
22 sub preprocess (@) {
23         my %params=@_;
24         my $pages=defined $params{pages} ? $params{pages} : "*";
25         
26         # Just get a list of all the pages, and count the items in it.
27         # Use a presence dependency to only update when pages are added
28         # or removed.
30         if ($pages eq '*') {
31                 # optimisation to avoid needing to try matching every page
32                 add_depends($params{page}, $pages, deptype("presence"));
33                 return scalar keys %pagesources;
34         }
36         return scalar pagespec_match_list($params{page}, $pages,
37                 deptype => deptype("presence"));
38 }
40 1