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;
|
|
|
|
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;
|
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>"
|
2006-08-19 00:22:47 +02:00
|
|
|
.IkiWiki::htmllink($params{page}, $params{destpage}, $item) ."\n";
|
|
|
|
$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
|