forked from jondot/awesome-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.rb
39 lines (33 loc) · 832 Bytes
/
validate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'parallel'
require 'nokogiri'
require 'open-uri'
require 'httparty'
require 'kramdown'
def check_link(uri)
code = HTTParty.head(uri, :follow_redirects => false).code
return code >= 200 && code < 400
end
BASE_URI = ENV['BASE_URI'] || 'https://github.com/jondot/awesome-react-native'
doc = Nokogiri::HTML(Kramdown::Document.new(open('README.md').read).to_html)
links = doc.css('a').to_a
puts "Validating #{links.count} links..."
invalids = []
Parallel.each(links, :in_threads => 4) do |link|
begin
uri = URI.join(BASE_URI, link.attr('href'))
check_link(uri)
putc('.')
rescue
putc('F')
invalids << "#{link} (reason: #{$!})"
end
end
unless invalids.empty?
puts "\n\nFailed links:"
invalids.each do |link|
puts "- #{link}"
end
puts "Done with errors."
exit(1)
end
puts "\nDone."