2 # Ikiwiki parentlinks plugin.
3 package IkiWiki::Plugin::parentlinks;
10 hook(type => "parentlinks", id => "parentlinks", call => \&parentlinks);
11 hook(type => "pagetemplate", id => "parentlinks", call => \&pagetemplate);
12 hook(type => "getsetup", id => "parentlinks", call => \&getsetup);
30 url => IkiWiki::baseurl(undef),
31 page => $config{wikiname},
37 my $title=$config{wikiname};
42 my @pagepath=(split("/", $page));
43 my $pagedepth=@pagepath;
45 # The last element in @pagepath is the page itself, so punt that
46 # (These are /parent/ links, after all.)
49 foreach my $dir (@pagepath) {
50 next if $dir eq 'index';
52 $height=($pagedepth - $depth);
54 $title=pagetitle($dir);
56 url => urlto(bestlink($page, $path), $page),
61 "height_$height" => 1,
68 sub pagetemplate (@) {
70 my $template=$params{template};
72 if ($template->query(name => "parentlinks") ||
73 $template->query(name => "has_parentlinks")) {
74 my @links=parentlinks($params{page});
75 $template->param(parentlinks => \@links);
76 $template->param(has_parentlinks => (@links > 0));