30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/blinkr/extensions/links.rb', line 30
def analyze(context, browser)
puts '----------------------'
puts " #{@links.length} links to check "
puts '----------------------'
start = DateTime.now
processed = 0
@links.select{|k| k.start_with? @config.base_url}.each do |url, locations|
link = URI.parse(url)
link.fragment = nil
link.query = nil
link.path = link.path.gsub(/\/+/, '/') if link.path
unless context.pages.keys.include?(link.to_s) || context.pages.keys.include?((link.to_s + '/'))
locations.each do |location|
location[:page].errors << Blinkr::Error.new({:severity => :warning,
:category => 'Resource missing from sitemap',
:type => '<a href=""> target missing from sitemap',
:url => url, :title => "#{url} (line #{location[:line]})",
:code => nil,
:message => 'Missing from sitemap',
:detail => 'Checked with Typheous',
:snippet => location[:snippet],
:icon => 'fa-bookmark-o'
})
end
end
end
@links.each do |url, metadata|
browser.process(url, @config.max_retrys, :method => :get, :followlocation => true, :timeout => 60,
:cookiefile => '_tmp/cookies', :cookiejar => '_tmp/cookies',
:connecttimeout => 30, :maxredirs => 3) do |resp|
puts "Loaded #{url} via #{browser.name} #{'(cached)' if resp.cached?}" if @config.verbose
resp_code = resp.code.to_i
if ((resp_code > 300 && resp_code < 400) && @config.warning_on_300s) || resp_code > 400
response = resp
detail = nil
if response.status_message.nil?
message = response.return_message
else
message = response.status_message
detail = response.return_message unless resp.return_message == 'No error'
end
severity = :danger
if response.code.to_i >= 300 && response.code.to_i < 400
severity = :warning
end
metadata.each do |src|
src[:page].errors << Blinkr::Error.new({:severity => severity,
:category => 'Resources missing',
:type => '<a href=""> target cannot be loaded',
:url => url, :title => "#{url} (line #{src[:line]})",
:code => response.code.to_i, :message => message,
:detail => detail, :snippet => src[:snippet],
:icon => 'fa-bookmark-o'}) unless response.success?
end
end
processed += 1
puts "Processed #{processed} of #{@links.size}" if @config.verbose
end
end
browser.hydra.run if browser.is_a? Blinkr::TyphoeusWrapper
puts "Total time in links: #{(DateTime.now.to_time - start.to_time).duration}" if @config.verbose
end
|