3 # Produce a hierarchical map of links.
5 # by Alessandro Dotti Contra <alessandro@hyboria.org>
8 package IkiWiki::Plugin::map;
15 hook(type => "preprocess", id => "map", call => \&preprocess);
18 sub preprocess (@) { #{{{
20 $params{pages}="*" unless defined $params{pages};
22 # Get all the items to map.
24 foreach my $page (keys %pagesources) {
25 if (pagespec_match($page, $params{pages}, location => $params{page})) {
26 push @mapitems, "/".$page;
30 # Needs to update whenever a page is added or removed, so
31 # register a dependency.
32 add_depends($params{page}, $params{pages});
33 # Explicitly add all currently shown pages, to detect when pages
35 add_depends($params{page}, join(" or ", @mapitems));
41 my $map = "<div class='map'>\n";
42 foreach my $item (sort @mapitems) {
43 my $depth = ($item =~ tr/\//\//);
44 my $baseitem=IkiWiki::dirname($item);
45 while (length $parent && length $baseitem && $baseitem !~ /^\Q$parent\E/) {
46 $parent=IkiWiki::dirname($parent);
50 while ($depth < $indent) {
54 while ($depth > $indent) {
57 if ($depth > $indent) {
65 $map .= "</li>\n" if $openli;
67 .htmllink($params{page}, $params{destpage}, $item)