]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/parentlinks.pm
switch to 1 parameter version of file_pruned
[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                         section => "core",
20                 },
21 }
22
23 sub parentlinks ($) {
24         my $page=shift;
25
26         my @ret;
27         my $path="";
28         my $title=$config{wikiname};
29         my $i=0;
30         my $depth=0;
31         my $height=0;
32
33         my @pagepath=(split("/", $page));
34         my $pagedepth=@pagepath;
35         foreach my $dir (@pagepath) {
36                 next if $dir eq 'index';
37                 $depth=$i;
38                 $height=($pagedepth - $depth);
39                 push @ret, {
40                         url => urlto(bestlink($page, $path), $page),
41                         page => $title,
42                         depth => $depth,
43                         height => $height,
44                         "depth_$depth" => 1,
45                         "height_$height" => 1,
46                 };
47                 $path.="/".$dir;
48                 $title=pagetitle($dir);
49                 $i++;
50         }
51         return @ret;
52 }
53
54 sub pagetemplate (@) {
55         my %params=@_;
56         my $page=$params{page};
57         my $template=$params{template};
58
59         if ($template->query(name => "parentlinks") ||
60            $template->query(name => "has_parentlinks")) {
61                 my @links=parentlinks($page);
62                 $template->param(parentlinks => \@links);
63                 $template->param(has_parentlinks => (@links > 0));
64         }
65 }
66
67 1