2 # Provides a list of pages no other page links to.
3 package IkiWiki::Plugin::orphans;
10 IkiWiki::hook(type => "preprocess", id => "orphans",
11 call => \&preprocess);
14 sub preprocess (@) { #{{{
16 $params{pages}="*" unless defined $params{pages};
18 # Needs to update whenever a page is added or removed, so
19 # register a dependency.
20 IkiWiki::add_depends($params{page}, $params{pages});
23 foreach my $p (keys %IkiWiki::links) {
24 map { $linkedto{IkiWiki::bestlink($p, $_)}=1 if length $_ }
25 @{$IkiWiki::links{$p}};
29 foreach my $page (keys %IkiWiki::renderedfiles) {
30 next if $linkedto{$page};
31 next unless IkiWiki::globlist_match($page, $params{pages});
32 # If the page has a link to some other page, it's
33 # indirectly linked to a page via that page's backlinks.
36 ($_ !~ /\/Discussion$/i || ! $IkiWiki::config{discussion}) &&
37 IkiWiki::bestlink($page, $_) !~ /^($page|)$/
38 } @{$IkiWiki::links{$page}};
42 return "All pages are linked to by other pages." unless @orphans;
43 return "<ul>\n".join("\n", map { "<li>".IkiWiki::htmllink($params{page}, $params{page}, $_, 1)."</li>" } sort @orphans)."</ul>\n";