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, which
58 # means the second (and following) calls to
59 # this function overwrite the previous one's
60 # reldepth values => known bug if PEDIGREE_BUT_ROOT and
61 # PEDIGREE_BUT_TWO_OLDEST are used in the same template
62 $parent->{reldepth}=($parent->{absdepth} - $offset);
69 sub pagetemplate (@) { #{{{
71 my $page=$params{page};
72 my $template=$params{template};
74 my @pedigree=pedigree($page)
75 if ($template->query(name => "pedigree")
76 or $template->query(name => "pedigree_but_root")
77 or $template->query(name => "pedigree_but_two_oldest")
80 $template->param(pedigree => \@pedigree)
81 if ($template->query(name => "pedigree"));
82 $template->param(pedigree_but_root => [forget_oldest(1, @pedigree)])
83 if ($template->query(name => "pedigree_but_root"));
84 $template->param(pedigree_but_two_oldest => [forget_oldest(2, @pedigree)])
85 if ($template->query(name => "pedigree_but_two_oldest"));