From 99292550fdf3c5bf9feb4a665e2de99f5cfc0d35 Mon Sep 17 00:00:00 2001 From: joey Date: Tue, 2 May 2006 06:15:31 +0000 Subject: * Add an orphans plugin for finding pages that nothing links to. * Removed backlinks page, which it turns out nothing used. --- IkiWiki/Plugin/orphans.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 IkiWiki/Plugin/orphans.pm (limited to 'IkiWiki/Plugin') 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 "\n"; +} # }}} + +1 -- cgit v1.2.3