From 2eac55e90efa6aa82f3159385f1398be4b3bf6da Mon Sep 17 00:00:00 2001 From: joey Date: Fri, 18 Aug 2006 16:18:45 +0000 Subject: * Add a map plugin contributed by Alessandro Dotti Contra. --- IkiWiki/Plugin/map.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 IkiWiki/Plugin/map.pm (limited to 'IkiWiki/Plugin') 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 +# +# 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 = "
\n"; + foreach my $item (sort @mapitems) { + my $depth = ($item =~ tr/\//\//) + 1; + next if exists $params{maxdepth} && $depth > $params{maxdepth}; + while ($depth < $indent) { + $indent--; + $map.="\n"; + } + while ($depth > $indent) { + $indent++; + $map.="
    \n"; + } + $map .= "
  • " + .IkiWiki::htmllink($params{page}, $params{destpage}, $item) + ."
  • \n"; + } + while ($indent > 0) { + $indent--; + $map.="
\n"; + } + $map .= "
\n"; + return $map; +} # }}} + +1 -- cgit v1.2.3