]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/parentlinks.pm
Merge branch 'master' into sipb
[ikiwiki.git] / IkiWiki / Plugin / parentlinks.pm
index 1ee69cbff4901695117e1d335f106d1dcb044367..bdf678069877b3c09bd29894d3f5d6b0353d2619 100644 (file)
@@ -16,6 +16,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => 1,
+                       section => "core",
                },
 }
 
@@ -31,10 +32,17 @@ sub parentlinks ($) {
 
        my @pagepath=(split("/", $page));
        my $pagedepth=@pagepath;
+
+       # The last element in @pagepath is the page itself, so punt that
+       # (These are /parent/ links, after all.)
+       pop @pagepath;
+
        foreach my $dir (@pagepath) {
                next if $dir eq 'index';
                $depth=$i;
                $height=($pagedepth - $depth);
+               $path.="/".$dir;
+               $title=pagetitle($dir);
                push @ret, {
                        url => urlto(bestlink($page, $path), $page),
                        page => $title,
@@ -43,8 +51,6 @@ sub parentlinks ($) {
                        "depth_$depth" => 1,
                        "height_$height" => 1,
                };
-               $path.="/".$dir;
-               $title=pagetitle($dir);
                $i++;
        }
        return @ret;
@@ -55,8 +61,11 @@ sub pagetemplate (@) {
         my $page=$params{page};
         my $template=$params{template};
 
-       if ($template->query(name => "parentlinks")) {
-               $template->param(parentlinks => [parentlinks($page)]);
+       if ($template->query(name => "parentlinks") ||
+          $template->query(name => "has_parentlinks")) {
+               my @links=parentlinks($page);
+               $template->param(parentlinks => \@links);
+               $template->param(has_parentlinks => (@links > 0));
        }
 }