summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/parentlinks.pm
blob: 728bbc399fe8b50e247318158a57bd5c2facad96 (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. section => "core",
  17. },
  18. }
  19. sub parentlinks ($) {
  20. my $page=shift;
  21. my @ret;
  22. my $path="";
  23. my $title=$config{wikiname};
  24. my $i=0;
  25. my $depth=0;
  26. my $height=0;
  27. my @pagepath=(split("/", $page));
  28. my $pagedepth=@pagepath;
  29. foreach my $dir (@pagepath) {
  30. next if $dir eq 'index';
  31. $depth=$i;
  32. $height=($pagedepth - $depth);
  33. push @ret, {
  34. url => urlto(bestlink($page, $path), $page),
  35. page => $title,
  36. depth => $depth,
  37. height => $height,
  38. "depth_$depth" => 1,
  39. "height_$height" => 1,
  40. };
  41. $path.="/".$dir;
  42. $title=pagetitle($dir);
  43. $i++;
  44. }
  45. return @ret;
  46. }
  47. sub pagetemplate (@) {
  48. my %params=@_;
  49. my $page=$params{page};
  50. my $template=$params{template};
  51. if ($template->query(name => "parentlinks") ||
  52. $template->query(name => "has_parentlinks")) {
  53. my @links=parentlinks($page);
  54. $template->param(parentlinks => \@links);
  55. $template->param(has_parentlinks => (@links > 0));
  56. }
  57. }
  58. 1