2 # -*- cperl-indent-level: 8; -*-
3 # Ikiwiki pedigree plugin.
4 package IkiWiki::Plugin::pedigree;
11 hook(type => "pagetemplate", id => "pedigree", call => \&pagetemplate);
14 sub pedigree ($) { #{{{
19 my $title=$config{wikiname};
22 my @pagepath=(split("/", $page));
23 my $pagedepth=@pagepath;
24 foreach my $dir (@pagepath) {
25 next if $dir eq 'index';
27 url => urlto($path, $page),
31 is_second_ancestor => ($i eq 1),
32 is_grand_mother => ($i eq ($pagedepth - 2)),
33 is_mother => ($i eq ($pagedepth - 1)),
36 $title=IkiWiki::pagetitle($dir);
42 sub forget_oldest ($@) { #{{{
47 unless ($offset ge scalar(@pedigree)) {
48 for (my $i=0; $i < $offset; $i++) {
52 # Doing so does not modify the original @pedigree, we've
53 # got our own copy of its "content" (i.e. a pile of
54 # references to hashes)...
55 $parent=shift @pedigree;
56 # ... but we have no copy of the referenced hashes, so we
57 # actually are modifying them in-place, but we don't care
58 # here since reldepth has to be computed everytime anyway.
59 $parent->{reldepth}=($parent->{absdepth} - $offset);
66 sub pagetemplate (@) { #{{{
68 my $page=$params{page};
69 my $template=$params{template};
71 if ($template->query(name => "pedigree")
72 or $template->query(name => "pedigree_but_root")
73 or $template->query(name => "pedigree_but_two_oldest")
76 my @pedigree=pedigree($page);
77 $template->param(pedigree => \@pedigree);
78 $template->param(pedigree_but_root => [forget_oldest(1, @pedigree)]);
79 $template->param(pedigree_but_two_oldest => [forget_oldest(2, @pedigree)]);