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