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