2006-08-18 18:18:45 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
2006-09-07 05:45:28 +02:00
|
|
|
# Produce a hierarchical map of links.
|
2006-08-18 18:18:45 +02:00
|
|
|
#
|
2006-08-19 07:05:02 +02:00
|
|
|
# by Alessandro Dotti Contra <alessandro@hyboria.org>
|
2006-08-18 18:18:45 +02:00
|
|
|
#
|
2006-08-19 00:22:47 +02:00
|
|
|
# Revision: 0.2
|
2006-08-18 18:18:45 +02:00
|
|
|
package IkiWiki::Plugin::map;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-08-18 18:18:45 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "map", call => \&preprocess);
|
2006-08-18 18:18:45 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
|
|
|
# Needs to update whenever a page is added or removed, so
|
|
|
|
# register a dependency.
|
2006-09-10 00:50:27 +02:00
|
|
|
add_depends($params{page}, $params{pages});
|
2006-08-18 18:18:45 +02:00
|
|
|
|
|
|
|
# Get all the items to map.
|
|
|
|
my @mapitems = ();
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $page (keys %links) {
|
2007-04-27 04:55:52 +02:00
|
|
|
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
2006-08-18 18:18:45 +02:00
|
|
|
push @mapitems, $page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create the map.
|
|
|
|
my $indent=0;
|
2006-08-19 00:22:47 +02:00
|
|
|
my $openli=0;
|
2006-08-18 18:18:45 +02:00
|
|
|
my $map = "<div class='map'>\n";
|
2006-08-19 00:22:47 +02:00
|
|
|
$map .= "<ul>\n";
|
2006-08-18 18:18:45 +02:00
|
|
|
foreach my $item (sort @mapitems) {
|
2006-08-19 00:22:47 +02:00
|
|
|
my $depth = ($item =~ tr/\//\//);
|
2006-08-18 18:18:45 +02:00
|
|
|
while ($depth < $indent) {
|
|
|
|
$indent--;
|
2006-08-19 00:22:47 +02:00
|
|
|
$map.="</li></ul>\n";
|
2006-08-18 18:18:45 +02:00
|
|
|
}
|
|
|
|
while ($depth > $indent) {
|
|
|
|
$indent++;
|
|
|
|
$map.="<ul>\n";
|
2006-08-19 00:22:47 +02:00
|
|
|
$openli=0;
|
2006-08-18 18:18:45 +02:00
|
|
|
}
|
2006-08-19 00:22:47 +02:00
|
|
|
$map .= "</li>\n" if $openli;
|
2006-08-18 18:18:45 +02:00
|
|
|
$map .= "<li>"
|
2007-02-20 04:05:47 +01:00
|
|
|
.htmllink($params{page}, $params{destpage}, $item)
|
|
|
|
."\n";
|
2006-08-19 00:22:47 +02:00
|
|
|
$openli=1;
|
2006-08-18 18:18:45 +02:00
|
|
|
}
|
|
|
|
while ($indent > 0) {
|
|
|
|
$indent--;
|
2006-08-19 00:22:47 +02:00
|
|
|
$map.="</li></ul>\n";
|
2006-08-18 18:18:45 +02:00
|
|
|
}
|
2006-08-19 00:22:47 +02:00
|
|
|
$map .= "</li></ul>\n";
|
2006-08-18 18:18:45 +02:00
|
|
|
$map .= "</div>\n";
|
|
|
|
return $map;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|