summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-05-02 06:15:31 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-05-02 06:15:31 +0000
commit99292550fdf3c5bf9feb4a665e2de99f5cfc0d35 (patch)
tree6454e784a83830461068034214a68d987bd231ff /IkiWiki
parentf84b47d080f4d1ac47d12bd45a7004a6aba5875f (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.pm40
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