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;
|
|
|
|
use IkiWiki 2.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-07-12 23:04:35 +02:00
|
|
|
} # }}}
|
|
|
|
|
2008-08-03 23:20:21 +02:00
|
|
|
sub getsetup () { #{{{
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
} #}}}
|
|
|
|
|
2008-07-15 16:25:39 +02: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-07-16 23:43:42 +02:00
|
|
|
url => urlto($path, $page),
|
|
|
|
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;
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub pagetemplate (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $template=$params{template};
|
|
|
|
|
2008-07-15 16:25:39 +02:00
|
|
|
if ($template->query(name => "parentlinks")) {
|
|
|
|
$template->param(parentlinks => [parentlinks($page)]);
|
2008-07-15 12:35:12 +02:00
|
|
|
}
|
2008-07-12 23:04:35 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|