]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/parentlinks.pm
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[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 3.00;
8
9 sub import {
10         hook(type => "parentlinks", id => "parentlinks", call => \&parentlinks);
11         hook(type => "pagetemplate", id => "parentlinks", call => \&pagetemplate);
12 }
13
14 sub getsetup () {
15         return 
16                 plugin => {
17                         safe => 1,
18                         rebuild => 1,
19                 },
20 }
21
22 sub parentlinks ($) {
23         my $page=shift;
24
25         my @ret;
26         my $path="";
27         my $title=$config{wikiname};
28         my $i=0;
29         my $depth=0;
30         my $height=0;
31
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(bestlink($page, $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=pagetitle($dir);
48                 $i++;
49         }
50         return @ret;
51 }
52
53 sub pagetemplate (@) {
54         my %params=@_;
55         my $page=$params{page};
56         my $template=$params{template};
57
58         if ($template->query(name => "parentlinks") ||
59            $template->query(name => "has_parentlinks")) {
60                 my @links=[parentlinks($page)];
61                 $template->param(parentlinks => \@links);
62                 $template->param(has_parentlinks => (@links > 0));
63         }
64 }
65
66 1