diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-05-02 06:15:31 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-05-02 06:15:31 +0000 |
commit | 99292550fdf3c5bf9feb4a665e2de99f5cfc0d35 (patch) | |
tree | 6454e784a83830461068034214a68d987bd231ff /IkiWiki | |
parent | f84b47d080f4d1ac47d12bd45a7004a6aba5875f (diff) |
* Add an orphans plugin for finding pages that nothing links to.
* Removed backlinks page, which it turns out nothing used.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/orphans.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm new file mode 100644 index 000000000..06b51bddc --- /dev/null +++ b/IkiWiki/Plugin/orphans.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# Provides a list of pages no other page links to. +package IkiWiki::Plugin::orphans; + +use warnings; +use strict; + +sub import { #{{{ + IkiWiki::register_plugin("preprocess", "orphans", \&preprocess); +} # }}} + +sub preprocess (@) { #{{{ + my %params=@_; + $params{pages}="*" unless defined $params{pages}; + + # Needs to update whenever a page is added or removed, so + # register a dependency. + IkiWiki::add_depends($params{page}, $params{pages}); + + my %linkedto; + foreach my $p (keys %IkiWiki::links) { + map { $linkedto{IkiWiki::bestlink($p, $_)}=1 if length $_ } + @{$IkiWiki::links{$p}}; + } + + my @orphans; + foreach my $page (keys %IkiWiki::renderedfiles) { + next if $linkedto{$page}; + next unless IkiWiki::globlist_match($page, $params{pages}); + # If the page has a link to some other page, it's + # indirectly linked to a page via that page's backlinks. + next if grep { length $_ && $_ !~/\/Discussion$/i && IkiWiki::bestlink($page, $_) ne $page } @{$IkiWiki::links{$page}}; + push @orphans, $page; + } + + return "All pages are linked to by other pages." unless @orphans; + return "<ul>\n".join("\n", map { "<li>".IkiWiki::htmllink($params{page}, $_, 1)."</li>" } sort @orphans)."</ul>\n"; +} # }}} + +1 |