<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Ikiwiki parentlinks plugin.
package IkiWiki::Plugin::parentlinks;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "parentlinks", id =&gt; "parentlinks", call =&gt; \&amp;parentlinks);
	hook(type =&gt; "pagetemplate", id =&gt; "parentlinks", call =&gt; \&amp;pagetemplate);
	hook(type =&gt; "getsetup", id =&gt; "parentlinks", call =&gt; \&amp;getsetup);
}

sub getsetup () {
	return 
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1,
			section =&gt; "core",
		},
}

sub parentlinks ($) {
	my $page=shift;

	if (! length $page) {
		# dynamic page
		return {
			url =&gt; $config{url},
			page =&gt; $config{wikiname},
		};
	}

	my @ret;
	my $path="";
	my $title=$config{wikiname};
	my $i=0;
	my $depth=0;
	my $height=0;

	my @pagepath=(split("/", $page));
	my $pagedepth=@pagepath;
	foreach my $dir (@pagepath) {
		next if $dir eq 'index';
		$depth=$i;
		$height=($pagedepth - $depth);
		push @ret, {
			url =&gt; urlto(bestlink($page, $path), $page),
			page =&gt; $title,
			depth =&gt; $depth,
			height =&gt; $height,
			"depth_$depth" =&gt; 1,
			"height_$height" =&gt; 1,
		};
		$path.="/".$dir;
		$title=pagetitle($dir);
		$i++;
	}
	return @ret;
}

sub pagetemplate (@) {
	my %params=@_;
        my $template=$params{template};

	if ($template-&gt;query(name =&gt; "parentlinks") ||
 	   $template-&gt;query(name =&gt; "has_parentlinks")) {
		my @links=parentlinks($params{page});
		$template-&gt;param(parentlinks =&gt; \@links);
		$template-&gt;param(has_parentlinks =&gt; (@links &gt; 0));
	}
}

1
</pre></body></html>