]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/parentlinks.pm
properly support all types of data in arrays
[ikiwiki.git] / IkiWiki / Plugin / parentlinks.pm
1 #!/usr/bin/perl
2 # Ikiwiki parentlinks plugin.
3 package IkiWiki::Plugin::parentlinks;
4
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
8
9 sub import { #{{{
10         hook(type => "pagetemplate", id => "parentlinks", call => \&pagetemplate);
11 } # }}}
12
13 sub parentlinks ($) { #{{{
14         my $page=shift;
15
16         my @ret;
17         my $path="";
18         my $title=$config{wikiname};
19         my $i=0;
20         my $depth=0;
21         my $height=0;
22
23         my @pagepath=(split("/", $page));
24         my $pagedepth=@pagepath;
25         foreach my $dir (@pagepath) {
26                 next if $dir eq 'index';
27                 $depth=$i;
28                 $height=($pagedepth - $depth);
29                 push @ret, {
30                         url => urlto($path, $page),
31                         page => $title,
32                         depth => $depth,
33                         height => $height,
34                         "depth_$depth" => 1,
35                         "height_$height" => 1,
36                 };
37                 $path.="/".$dir;
38                 $title=IkiWiki::pagetitle($dir);
39                 $i++;
40         }
41         return @ret;
42 } #}}}
43
44 sub pagetemplate (@) { #{{{
45         my %params=@_;
46         my $page=$params{page};
47         my $template=$params{template};
48
49         if ($template->query(name => "parentlinks")) {
50                 $template->param(parentlinks => [parentlinks($page)]);
51         }
52 } # }}}
53
54 1