supprimé
[cyclowiki.git] / .ikiwiki / lib / IkiWiki / Plugin / parentlinks_fixed.pm
1 #!/usr/bin/perl
2 # Ikiwiki parentlinks plugin.
3 package IkiWiki::Plugin::parentlinks_fixed;
4
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
8
9 sub import {
10 hook(type => "parentlinks", id => "parentlinks_fixed", call => \&parentlinks);
11 hook(type => "pagetemplate", id => "parentlinks_fixed", call => \&pagetemplate);
12 hook(type => "getsetup", id => "parentlinks_fixed", call => \&getsetup);
13 }
14
15 sub getsetup () {
16 return
17 plugin => {
18 safe => 1,
19 rebuild => 1,
20 section => "core",
21 },
22 }
23
24 sub parentlinks ($$) {
25 my $page=shift;
26 my $destpage=shift;
27
28 if (! length $page) {
29 # dynamic page
30 return {
31 url => IkiWiki::baseurl(undef),
32 page => $config{wikiname},
33 };
34 }
35
36 my @ret;
37 my $path="";
38 my $title=$config{wikiname};
39 my $i=0;
40 my $depth=0;
41 my $height=0;
42
43 my @pagepath=(split("/", $page));
44 my $pagedepth=@pagepath;
45 foreach my $dir (@pagepath) {
46 next if $dir eq 'index';
47 $depth=$i;
48 $height=($pagedepth - $depth);
49 push @ret, {
50 url => urlto(bestlink($destpage, $path), $destpage),
51 page => $title,
52 depth => $depth,
53 height => $height,
54 "depth_$depth" => 1,
55 "height_$height" => 1,
56 };
57 $path.="/".$dir;
58 $title=pagetitle($dir);
59 $i++;
60 }
61 return @ret;
62 }
63
64 sub pagetemplate (@) {
65 my %params=@_;
66 my $template=$params{template};
67
68 if ($template->query(name => "parentlinks") ||
69 $template->query(name => "has_parentlinks")) {
70 my @links=parentlinks($params{page}, $params{destpage});
71 $template->param(parentlinks => \@links);
72 $template->param(has_parentlinks => (@links > 0));
73 }
74 }
75
76 1