<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::pagecount;

use warnings;
use strict;
use IkiWiki 2.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "pagecount", call =&gt; \&amp;getsetup);
	hook(type =&gt; "preprocess", id =&gt; "pagecount", call =&gt; \&amp;preprocess);
}

sub getsetup () {
	return 
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; undef,
		},
}

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.
	add_depends($params{page}, $params{pages});
	
	my @pages=keys %pagesources;
	return $#pages+1 if $params{pages} eq "*"; # optimisation
	my $count=0;
	foreach my $page (@pages) {
		$count++ if pagespec_match($page, $params{pages}, location =&gt; $params{page});
	}
	return $count;
}

1
</pre></body></html>