aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/map.pm61
-rwxr-xr-xMakefile.PL2
-rw-r--r--debian/changelog3
-rw-r--r--doc/ikiwiki.setup2
-rw-r--r--doc/plugins/map.mdwn16
5 files changed, 81 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
new file mode 100644
index 000000000..c65e61ac9
--- /dev/null
+++ b/IkiWiki/Plugin/map.pm
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+#
+# Produce a hyerarchical map of links.
+#
+# By Alessandro Dotti Contra <alessandro@hyboria.org>
+#
+# Revision: 0.1
+package IkiWiki::Plugin::map;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+sub import { #{{{
+ IkiWiki::hook(type => "preprocess", id => "map",
+ call => \&preprocess);
+} # }}}
+
+sub preprocess (@) { #{{{
+ my %params=@_;
+ $params{pages}="*" unless defined $params{pages};
+
+ # Needs to update whenever a page is added or removed, so
+ # register a dependency.
+ IkiWiki::add_depends($params{page}, $params{pages});
+
+ # Get all the items to map.
+ my @mapitems = ();
+ foreach my $page (keys %IkiWiki::links) {
+ if (IkiWiki::pagespec_match($page, $params{pages})) {
+ push @mapitems, $page;
+ }
+ }
+
+ # Create the map.
+ my $indent=0;
+ my $map = "<div class='map'>\n";
+ foreach my $item (sort @mapitems) {
+ my $depth = ($item =~ tr/\//\//) + 1;
+ next if exists $params{maxdepth} && $depth > $params{maxdepth};
+ while ($depth < $indent) {
+ $indent--;
+ $map.="</ul>\n";
+ }
+ while ($depth > $indent) {
+ $indent++;
+ $map.="<ul>\n";
+ }
+ $map .= "<li>"
+ .IkiWiki::htmllink($params{page}, $params{destpage}, $item)
+ ."</li>\n";
+ }
+ while ($indent > 0) {
+ $indent--;
+ $map.="</ul>\n";
+ }
+ $map .= "</div>\n";
+ return $map;
+} # }}}
+
+1
diff --git a/Makefile.PL b/Makefile.PL
index 1f46e9c95..2ef99fa80 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -23,7 +23,7 @@ extra_build:
--plugin=brokenlinks --plugin=pagecount \
--plugin=orphans --plugin=haiku --plugin=meta \
--plugin=tag --plugin=polygen --plugin=pagestats \
- --plugin=fortune --plugin=aggregate
+ --plugin=fortune --plugin=aggregate --plugin=map
./mdwn2man ikiwiki 1 doc/usage.mdwn > ikiwiki.man
./mdwn2man ikiwiki-mass-rebuild 8 doc/ikiwiki-mass-rebuild.mdwn > ikiwiki-mass-rebuild.man
diff --git a/debian/changelog b/debian/changelog
index d1dac85e1..787faa928 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,8 +9,9 @@ ikiwiki (1.21) UNRELEASED; urgency=low
* Clean up yes/no parameter parsing in inline plugin.
* Implemented better cycle detection in the inline plugin; nested inlines
will now work.
+ * Add a map plugin contributed by Alessandro Dotti Contra.
- -- Joey Hess <joeyh@debian.org> Thu, 17 Aug 2006 23:27:38 -0400
+ -- Joey Hess <joeyh@debian.org> Fri, 18 Aug 2006 12:10:37 -0400
ikiwiki (1.20) unstable; urgency=low
diff --git a/doc/ikiwiki.setup b/doc/ikiwiki.setup
index a0ce5a468..678dece23 100644
--- a/doc/ikiwiki.setup
+++ b/doc/ikiwiki.setup
@@ -81,7 +81,7 @@ use IkiWiki::Setup::Standard {
# To add plugins, list them here.
#add_plugins => [qw{meta tag pagecount brokenlinks search smiley
# wikitext camelcase pagestats htmltidy fortune
- # sidebar}],
+ # sidebar map}],
# If you want to disable any of the default plugins, list them here.
#disable_plugins => [qw{inline htmlscrubber}],
}
diff --git a/doc/plugins/map.mdwn b/doc/plugins/map.mdwn
new file mode 100644
index 000000000..039ed559e
--- /dev/null
+++ b/doc/plugins/map.mdwn
@@ -0,0 +1,16 @@
+This plugin generates a hierarchical page map for the wiki. Example usage:
+
+ \[[map pages="* and !blog/*" maxdepth=2]]
+
+If the pages to include are not specified, all pages (and other files) in
+the wiki are mapped. If the maxdepth parameter is passed, only pages nested
+less than that many levels deep will be included in the map.
+
+This plugin is included in ikiwiki, but is not enabled by default.
+
+If this plugin is enabled, here is a page map for the plugins section
+of this wiki:
+
+[[map pages="plugins or plugins/*" maxdepth=3]]
+
+[[tag type/meta]]