summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/orphans.pm
blob: 3a8a7954fe1dd6e5c49b5ba12a7f5ec6557e6fa6 (plain)
  1. #!/usr/bin/perl
  2. # Provides a list of pages no other page links to.
  3. package IkiWiki::Plugin::orphans;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. sub import { #{{{
  8. hook(type => "preprocess", id => "orphans", call => \&preprocess);
  9. } # }}}
  10. sub preprocess (@) { #{{{
  11. my %params=@_;
  12. $params{pages}="*" unless defined $params{pages};
  13. # Needs to update whenever a page is added or removed, so
  14. # register a dependency.
  15. add_depends($params{page}, $params{pages});
  16. my %linkedto;
  17. foreach my $p (keys %links) {
  18. map { $linkedto{bestlink($p, $_)}=1 if length $_ }
  19. @{$links{$p}};
  20. }
  21. my @orphans;
  22. foreach my $page (keys %renderedfiles) {
  23. next if $linkedto{$page};
  24. next unless pagespec_match($page, $params{pages});
  25. # If the page has a link to some other page, it's
  26. # indirectly linked to a page via that page's backlinks.
  27. next if grep {
  28. length $_ &&
  29. ($_ !~ /\/Discussion$/i || ! $config{discussion}) &&
  30. bestlink($page, $_) !~ /^($page|)$/
  31. } @{$links{$page}};
  32. push @orphans, $page;
  33. }
  34. return "All pages are linked to by other pages." unless @orphans;
  35. return "<ul>\n".join("\n", map { "<li>".htmllink($params{page}, $params{destpage}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
  36. } # }}}
  37. 1