2 # Provides a list of broken links.
3 package IkiWiki::Plugin::brokenlinks;
10 IkiWiki::hook(type => "preprocess", id => "brokenlinks",
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 $page (%IkiWiki::links) {
24 if (IkiWiki::globlist_match($page, $params{pages})) {
25 foreach my $link (@{$IkiWiki::links{$page}}) {
26 next if $link =~ /.*\/discussion/i && $IkiWiki::config{discussion};
27 my $bestlink=IkiWiki::bestlink($page, $link);
28 next if length $bestlink;
30 IkiWiki::htmllink($page, $params{destpage}, $link, 1).
32 IkiWiki::htmllink($params{page}, $params{destpage}, $page, 1);
37 return "There are no broken links!" unless @broken;
39 return "<ul>\n".join("\n", map { "<li>$_</li>" } grep { ! $seen{$_}++ } sort @broken)."</ul>\n";