Created
March 6, 2013 04:16
-
-
Save tfausak/5096655 to your computer and use it in GitHub Desktop.
Check for link rot in a GitHub Pages repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
pattern = /^\[[0-9]+\]: (http.*)$/i | |
Dir.glob('./_posts/*.md').sort.each do |file| | |
puts file | |
File.open(file).each_line do |line| | |
match = pattern.match(line) | |
if match | |
uri = URI(match[1]) | |
Net::HTTP.start( | |
uri.host, | |
uri.port, | |
:use_ssl => uri.scheme == 'https' | |
) do |http| | |
request = Net::HTTP::Head.new(uri.request_uri) | |
response = http.request(request) | |
case response | |
when Net::HTTPOK then | |
puts "\033[32m\u2713 #{uri}\033[0m" | |
else | |
puts "\033[31m\u2716 #{uri}\033[0m" | |
end | |
end | |
sleep(1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment