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