summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/map.pm
blob: 3c41194f47f32cf51f782c72a1c74a085a98e21e (plain)
  1. #!/usr/bin/perl
  2. #
  3. # Produce a hierarchical map of links.
  4. #
  5. # by Alessandro Dotti Contra <alessandro@hyboria.org>
  6. #
  7. # Revision: 0.2
  8. package IkiWiki::Plugin::map;
  9. use warnings;
  10. use strict;
  11. use IkiWiki;
  12. sub import { #{{{
  13. hook(type => "preprocess", id => "map", call => \&preprocess);
  14. } # }}}
  15. sub preprocess (@) { #{{{
  16. my %params=@_;
  17. $params{pages}="*" unless defined $params{pages};
  18. # Needs to update whenever a page is added or removed, so
  19. # register a dependency.
  20. add_depends($params{page}, $params{pages});
  21. # Get all the items to map.
  22. my @mapitems = ();
  23. foreach my $page (keys %links) {
  24. if (pagespec_match($page, $params{pages}, $params{page})) {
  25. push @mapitems, $page;
  26. }
  27. }
  28. # Create the map.
  29. my $indent=0;
  30. my $openli=0;
  31. my $map = "<div class='map'>\n";
  32. $map .= "<ul>\n";
  33. foreach my $item (sort @mapitems) {
  34. my $depth = ($item =~ tr/\//\//);
  35. while ($depth < $indent) {
  36. $indent--;
  37. $map.="</li></ul>\n";
  38. }
  39. while ($depth > $indent) {
  40. $indent++;
  41. $map.="<ul>\n";
  42. $openli=0;
  43. }
  44. $map .= "</li>\n" if $openli;
  45. $map .= "<li>"
  46. .htmllink($params{page}, $params{destpage}, $item) ."\n";
  47. $openli=1;
  48. }
  49. while ($indent > 0) {
  50. $indent--;
  51. $map.="</li></ul>\n";
  52. }
  53. $map .= "</li></ul>\n";
  54. $map .= "</div>\n";
  55. return $map;
  56. } # }}}
  57. 1