22
23
24
25
26
27
28
29
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
|
# File 'app/models/wco/sitemap_path.rb', line 22
def check
self.status = 'NOT_OK'
skip_rest = false
if self[:selector].present?
begin
body = HTTParty.get( "#{site.origin}#{self[:path]}" ).body
rescue OpenSSL::SSL::SSLError => err
results.push "NOT OK [ssl-exception] #{self[:path]}"
return
end
doc = Nokogiri::HTML( body )
out = doc.search self[:selector]
if out.present?
results.push "OK #{self[:path]}"
self.status = 'OK'
else
results.push "NOT OK [selector-missing] #{self[:path]}"
end
elsif self[:redirect_to].present?
out = HTTParty.get( "#{site.origin}#{self[:path]}", follow_redirects: false )
if( out.[:location] == self[:redirect_to] ||
out.[:location] == "#{site.origin}#{self[:redirect_to]}" )
results.push "OK #{self[:path]}"
self.status = 'OK'
else
results.push "NOT OK [redirect-missing] #{self[:path]}"
puts!( out.response, 'response' ) if DEBUG
puts "NOT OK #{self[:path]}"
puts out.[:location]
puts self[:redirect_to]
end
skip_rest = true
else
results.push "SKIP #{self[:path]}"
self.status = 'OK'
skip_rest = true
end
if !skip_rest
if self[:meta_description].present?
out = doc.search( 'head meta[name="description"]' )[0]['content']
if out.include?( self[:meta_description] )
results.push "OK #{self[:path]} meta_description"
else
self.status = 'NOT_OK'
results.push "NOT OK [meta-description-no-contain] #{self[:path]}"
end
end
if self[:selectors].present?
self[:selectors].each do |selector|
out = doc.search selector
if out.present?
results.push "OK #{self[:path]} selectors:#{selector}"
else
self.status = 'NOT_OK'
results.push "NOT OK [selectors-missing:#{selector}] #{self[:path]}"
end
end
end
if self[:title].present?
out = doc.search( 'head title' )[0].text
if out.include?( self[:title] )
results.push "OK #{self[:path]} title"
else
self.status = 'NOT_OK'
results.push "NOT OK [title-no-contain] #{self[:path]}"
end
end
end
self.save
end
|