Skip to content
This repository
Browse code

Add :ilinks task to display broken internal links.

  • Loading branch information...
commit 5871e9e22cbaaf38b50a1f03e1ed4e4d1e7249bf 1 parent bb86bfe
runpaint authored

Showing 1 changed file with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. +18 0 Rakefile
18 Rakefile
@@ -13,3 +13,21 @@ end
13 13
14 14 task :pdf => ['output/vim-recipes.pdf'] do
15 15 end
  16 +
  17 +task :ilinks => ['output/all.html'] do |t|
  18 + require 'hpricot'
  19 + target = {}
  20 + source = {}
  21 + FileList['text/**/*.html'].each do |file|
  22 + doc = Hpricot(File.open(file, 'r'))
  23 + doc.search("a[@href*='#']").each do |a|
  24 + source[a['href'][/[^#]+/]] = file
  25 + end
  26 + doc.search("*[@id]").each do |e|
  27 + target[e['id']] = 1
  28 + end
  29 + end
  30 + source.keys.each do |s|
  31 + $stderr.puts "Link #{s} from #{source[s]} is broken" unless target.key? s
  32 + end
  33 +end

0 comments on commit 5871e9e

Please sign in to comment.
Something went wrong with that request. Please try again.