summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/parentlinks.pm
blob: eb8bfa83b38076ff7b1dd833a5d2f8a92b6a2981 (plain)
  1. #!/usr/bin/perl
  2. # -*- cperl-indent-level: 8; -*-
  3. # Ikiwiki pedigree plugin.
  4. package IkiWiki::Plugin::pedigree;
  5. use warnings;
  6. use strict;
  7. use IkiWiki 2.00;
  8. sub import { #{{{
  9. hook(type => "pagetemplate", id => "pedigree", call => \&pagetemplate);
  10. } # }}}
  11. sub pedigree ($) { #{{{
  12. my $page=shift;
  13. my @ret;
  14. my $path="";
  15. my $title=$config{wikiname};
  16. my $i=0;
  17. my $depth=0;
  18. my $height=0;
  19. my @pagepath=(split("/", $page));
  20. my $pagedepth=@pagepath;
  21. foreach my $dir (@pagepath) {
  22. next if $dir eq 'index';
  23. $depth=$i;
  24. $height=($pagedepth - $depth);
  25. push @ret, {
  26. url => urlto($path, $page),
  27. page => $title,
  28. depth => $depth,
  29. height => $height,
  30. "depth_$depth" => 1,
  31. "height_$height" => 1,
  32. };
  33. $path.="/".$dir;
  34. $title=IkiWiki::pagetitle($dir);
  35. $i++;
  36. }
  37. return @ret;
  38. } #}}}
  39. sub pagetemplate (@) { #{{{
  40. my %params=@_;
  41. my $page=$params{page};
  42. my $template=$params{template};
  43. if ($template->query(name => "pedigree")) {
  44. $template->param(pedigree => [pedigree($page)]);
  45. }
  46. } # }}}
  47. 1