2008-07-12 23:04:35 +02:00
|
|
|
#!/usr/bin/perl
|
2008-07-15 16:25:39 +02:00
|
|
|
# Ikiwiki parentlinks plugin.
|
|
|
|
package IkiWiki::Plugin::parentlinks;
|
2008-07-12 23:04:35 +02:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-07-12 23:04:35 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "parentlinks", id => "parentlinks", call => \&parentlinks);
|
2008-07-15 16:25:39 +02:00
|
|
|
hook(type => "pagetemplate", id => "parentlinks", call => \&pagetemplate);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-12 23:04:35 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 23:20:21 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 23:20:21 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub parentlinks ($) {
|
2008-07-12 23:04:35 +02:00
|
|
|
my $page=shift;
|
|
|
|
|
|
|
|
my @ret;
|
|
|
|
my $path="";
|
|
|
|
my $title=$config{wikiname};
|
2008-07-13 14:51:20 +02:00
|
|
|
my $i=0;
|
2008-07-15 12:35:12 +02:00
|
|
|
my $depth=0;
|
|
|
|
my $height=0;
|
2008-07-12 23:04:35 +02:00
|
|
|
|
|
|
|
my @pagepath=(split("/", $page));
|
2008-07-13 14:51:20 +02:00
|
|
|
my $pagedepth=@pagepath;
|
2008-07-12 23:04:35 +02:00
|
|
|
foreach my $dir (@pagepath) {
|
|
|
|
next if $dir eq 'index';
|
2008-07-15 12:35:12 +02:00
|
|
|
$depth=$i;
|
|
|
|
$height=($pagedepth - $depth);
|
2008-07-12 23:04:35 +02:00
|
|
|
push @ret, {
|
2008-11-12 17:36:00 +01:00
|
|
|
url => urlto(bestlink($page, $path), $page),
|
2008-07-16 23:43:42 +02:00
|
|
|
page => $title,
|
|
|
|
depth => $depth,
|
|
|
|
height => $height,
|
|
|
|
"depth_$depth" => 1,
|
|
|
|
"height_$height" => 1,
|
|
|
|
};
|
2008-07-12 23:04:35 +02:00
|
|
|
$path.="/".$dir;
|
2008-09-27 20:14:36 +02:00
|
|
|
$title=pagetitle($dir);
|
2008-07-12 23:04:35 +02:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return @ret;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-12 23:04:35 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub pagetemplate (@) {
|
2008-07-12 23:04:35 +02:00
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $template=$params{template};
|
|
|
|
|
2009-09-27 23:40:41 +02:00
|
|
|
if ($template->query(name => "parentlinks") ||
|
|
|
|
$template->query(name => "has_parentlinks")) {
|
2009-09-29 19:33:23 +02:00
|
|
|
my @links=parentlinks($page);
|
2009-09-27 23:40:41 +02:00
|
|
|
$template->param(parentlinks => \@links);
|
|
|
|
$template->param(has_parentlinks => (@links > 0));
|
2008-07-15 12:35:12 +02:00
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-12 23:04:35 +02:00
|
|
|
|
|
|
|
1
|