From 2b0c8d167e8b98d11e3504393fe4b98596dfd891 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Thu, 18 Jun 2009 18:25:46 +0100
Subject: [PATCH 1/3] pagestats: when making a tag cloud, don't emit links
where the tag is unused
---
IkiWiki/Plugin/pagestats.pm | 2 ++
1 file changed, 2 insertions(+)
diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
index 8ab5d3666..5dd2f337b 100644
--- a/IkiWiki/Plugin/pagestats.pm
+++ b/IkiWiki/Plugin/pagestats.pm
@@ -63,6 +63,8 @@ sub preprocess (@) {
my $res = "
\n";
foreach my $page (sort keys %counts) {
+ next unless $counts{$page} > 0;
+
my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
$res .= "".
htmllink($params{page}, $params{destpage}, $page).
From 9c13e29d4fbb85a83b0ed5fd7271d7c1688fbc07 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Thu, 18 Jun 2009 18:27:00 +0100
Subject: [PATCH 2/3] IkiWiki::Render: split out backlink_pages() function from
backlinks()
This separates style from content - backlinks() performs lossy
transformations on the page names to get it in the form that the page
template wants.
---
IkiWiki/Render.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 2da18738d..6900d5eed 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -24,13 +24,19 @@ sub calculate_backlinks () {
$backlinks_calculated=1;
}
-sub backlinks ($) {
+sub backlink_pages ($) {
my $page=shift;
calculate_backlinks();
+ return keys %{$backlinks{$page}};
+}
+
+sub backlinks ($) {
+ my $page=shift;
+
my @links;
- foreach my $p (keys %{$backlinks{$page}}) {
+ foreach my $p (backlink_pages($page)) {
my $href=urlto($p, $page);
# Trim common dir prefixes from both pages.
From acb79b5c00b48c4b52a29703e9d7b52330fd23b2 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Thu, 18 Jun 2009 18:33:49 +0100
Subject: [PATCH 3/3] pagestats: add `among` parameter, which only counts links
from specified pages
---
IkiWiki/Plugin/pagestats.pm | 11 ++++++++++-
doc/ikiwiki/directive/pagestats.mdwn | 10 ++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
index 5dd2f337b..874ead7e6 100644
--- a/IkiWiki/Plugin/pagestats.pm
+++ b/IkiWiki/Plugin/pagestats.pm
@@ -38,13 +38,22 @@ sub preprocess (@) {
# Needs to update whenever a page is added or removed, so
# register a dependency.
add_depends($params{page}, $params{pages});
+ add_depends($params{page}, $params{among}) if exists $params{among};
my %counts;
my $max = 0;
foreach my $page (pagespec_match_list([keys %links],
$params{pages}, location => $params{page})) {
use IkiWiki::Render;
- $counts{$page} = scalar(IkiWiki::backlinks($page));
+
+ my @backlinks = IkiWiki::backlink_pages($page);
+
+ if (exists $params{among}) {
+ @backlinks = pagespec_match_list(\@backlinks,
+ $params{among}, location => $params{page});
+ }
+
+ $counts{$page} = scalar(@backlinks);
$max = $counts{$page} if $counts{$page} > $max;
}
diff --git a/doc/ikiwiki/directive/pagestats.mdwn b/doc/ikiwiki/directive/pagestats.mdwn
index cfb5737a5..426f3e4af 100644
--- a/doc/ikiwiki/directive/pagestats.mdwn
+++ b/doc/ikiwiki/directive/pagestats.mdwn
@@ -12,4 +12,14 @@ And here's how to create a table of all the pages on the wiki:
\[[!pagestats style="table"]]
+The optional `among` parameter limits counting to pages that match a
+[[ikiwiki/PageSpec]]. For instance, to display a cloud of tags used on blog
+entries, you could use:
+
+ \[[!pagestats pages="tags/*" among="blog/posts/*"]]
+
+or to display a cloud of tags related to Linux, you could use:
+
+ \[[!pagestats pages="tags/* and not tags/linux" among="tagged(linux)"]]
+
[[!meta robots="noindex, follow"]]