colorful rat Ratfactor.com > Dave's Repos

rat-tools

Tools I use to build and maintain this website.
git clone http://ratfactor.com/repos/rat-tools/rat-tools.git

rat-tools/getlinks.rb

Download raw file: getlinks.rb

1 #!/usr/bin/ruby 2 3 # try getlinks.rb > src/all_links.html 4 5 require 'pathname' 6 7 site_root = "src/" 8 9 Pathname.glob("#{site_root}**/*.adoc").each do |infile| 10 page = infile.sub(/^#{site_root}/,'') # remove root from page path 11 page_dir = page.dirname 12 #puts "<h3>#{page}</h3>" 13 #puts "#{page} - #{page_dir}<br>" 14 15 File.open(infile).each do |line| 16 links = line.scan(/link:[^\]]*\]/) 17 links.each do |link_chunk| 18 m = /^link:(.*)\[(.*)\]$/.match(link_chunk) 19 20 link = m[1] 21 desc = m[2] 22 23 # this can skip external links 24 if link =~ /^http/ 25 next 26 end 27 28 if link =~ /^\/|\/$/ 29 puts "<span style=\"background: pink\">slash</span>" 30 end 31 32 puts "<a href=\"#{page_dir}/#{link}\">#{link}</a> (#{infile})<br>" 33 end 34 end 35 end 36