]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/parentlinks.pm
Add hook class at-top for featured block so we can restore whitespace.
[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
35         # The last element in @pagepath is the page itself, so punt that
36         # (These are /parent/ links, after all.)
37         pop @pagepath;
38
39         foreach my $dir (@pagepath) {
40                 next if $dir eq 'index';
41                 $depth=$i;
42                 $height=($pagedepth - $depth);
43                 $path.="/".$dir;
44                 $title=pagetitle($dir);
45                 push @ret, {
46                         url => urlto($path, $page),
47                         page => $title,
48                         depth => $depth,
49                         height => $height,
50                         "depth_$depth" => 1,
51                         "height_$height" => 1,
52                 };
53                 $i++;
54         }
55         return @ret;
56 }
57
58 sub pagetemplate (@) {
59         my %params=@_;
60         my $page=$params{page};
61         my $template=$params{template};
62
63         if ($template->query(name => "parentlinks")) {
64                 $template->param(parentlinks => [parentlinks($page)]);
65         }
66 }
67
68 1