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