summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/orphans.pm
blob: bd3c6b8b9f8e4157856417847458832fbe731d26 (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. IkiWiki::register_plugin("preprocess", "orphans", \&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. IkiWiki::add_depends($params{page}, $params{pages});
  16. my %linkedto;
  17. foreach my $p (keys %IkiWiki::links) {
  18. map { $linkedto{IkiWiki::bestlink($p, $_)}=1 if length $_ }
  19. @{$IkiWiki::links{$p}};
  20. }
  21. my @orphans;
  22. foreach my $page (keys %IkiWiki::renderedfiles) {
  23. next if $linkedto{$page};
  24. next unless IkiWiki::globlist_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 { length $_ && $_ !~/\/Discussion$/i && IkiWiki::bestlink($page, $_) ne $page } @{$IkiWiki::links{$page}};
  28. push @orphans, $page;
  29. }
  30. return "All pages are linked to by other pages." unless @orphans;
  31. return "<ul>\n".join("\n", map { "<li>".IkiWiki::htmllink($params{page}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
  32. } # }}}
  33. 1