]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/map.pm
* Fix aggregator to not warn when a feed contains no body content at all.
[ikiwiki.git] / IkiWiki / Plugin / map.pm
1 #!/usr/bin/perl
2 #
3 # Produce a hierarchical map of links.
4 #
5 # by Alessandro Dotti Contra <alessandro@hyboria.org>
6 #
7 # Revision: 0.2
8 package IkiWiki::Plugin::map;
9
10 use warnings;
11 use strict;
12 use IkiWiki;
13
14 sub import { #{{{
15         hook(type => "preprocess", id => "map", call => \&preprocess);
16 } # }}}
17
18 sub preprocess (@) { #{{{
19         my %params=@_;
20         $params{pages}="*" unless defined $params{pages};
21         
22         # Needs to update whenever a page is added or removed, so
23         # register a dependency.
24         add_depends($params{page}, $params{pages});
25         
26         # Get all the items to map.
27         my @mapitems = ();
28         foreach my $page (keys %links) {
29                 if (pagespec_match($page, $params{pages}, $params{page})) {
30                         push @mapitems, $page;
31                 }
32         }
33
34         # Create the map.
35         my $indent=0;
36         my $openli=0;
37         my $map = "<div class='map'>\n";
38         $map .= "<ul>\n";
39         foreach my $item (sort @mapitems) {
40                 my $depth = ($item =~ tr/\//\//);
41                 while ($depth < $indent) {
42                         $indent--;
43                         $map.="</li></ul>\n";
44                 }
45                 while ($depth > $indent) {
46                         $indent++;
47                         $map.="<ul>\n";
48                         $openli=0;
49                 }
50                 $map .= "</li>\n" if $openli;
51                 $map .= "<li>"
52                         .htmllink($params{page}, $params{destpage}, $item)
53                         ."\n";
54                 $openli=1;
55         }
56         while ($indent > 0) {
57                 $indent--;
58                 $map.="</li></ul>\n";
59         }
60         $map .= "</li></ul>\n";
61         $map .= "</div>\n";
62         return $map;
63 } # }}}
64
65 1