2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Provides [[pagecount ]] to count the number of pages.
|
|
|
|
package IkiWiki::Plugin::pagecount;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2006-05-02 08:53:33 +02:00
|
|
|
use IkiWiki;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-05-03 21:58:58 +02:00
|
|
|
IkiWiki::hook(type => "preprocess", id => "pagecount",
|
|
|
|
call => \&preprocess);
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
|
|
|
# Needs to update count whenever a page is added or removed, so
|
|
|
|
# register a dependency.
|
|
|
|
IkiWiki::add_depends($params{page}, $params{pages});
|
|
|
|
|
|
|
|
my @pages=keys %IkiWiki::pagesources;
|
|
|
|
return $#pages+1 if $params{pages} eq "*"; # optimisation
|
|
|
|
my $count=0;
|
|
|
|
foreach my $page (@pages) {
|
2006-08-02 02:14:31 +02:00
|
|
|
$count++ if IkiWiki::pagespec_match($page, $params{pages});
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|