seo_checker 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/seo_checker.rb +19 -20
- data/seo_checker.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/seo_checker.rb
CHANGED
@@ -27,7 +27,11 @@ class SEOChecker
|
|
27
27
|
|
28
28
|
def check
|
29
29
|
begin
|
30
|
-
|
30
|
+
check_robot
|
31
|
+
check_sitemap("#{@url}/sitemap.xml") if @locations.empty?
|
32
|
+
check_sitemap("#{@url}/sitemap.xml.gz") if @locations.empty?
|
33
|
+
raise SEOException, "Error: There is no sitemap.xml or sitemap.xml.gz" if @locations.empty?
|
34
|
+
|
31
35
|
check_location
|
32
36
|
|
33
37
|
report
|
@@ -36,32 +40,27 @@ class SEOChecker
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
|
-
def
|
40
|
-
#TODO: allow manual sitemap file
|
41
|
-
check_plain_sitemap
|
42
|
-
check_gzip_sitemap if @locations.empty?
|
43
|
-
|
44
|
-
raise SEOException, "Error: There is no sitemap.xml or sitemap.xml.gz" if @locations.empty?
|
45
|
-
end
|
46
|
-
|
47
|
-
def check_plain_sitemap
|
48
|
-
@logger.debug "checking sitemap.xml file" if @logger
|
43
|
+
def check_robot
|
49
44
|
uri = URI.parse(@url)
|
50
|
-
uri.path = '/
|
45
|
+
uri.path = '/robots.txt'
|
51
46
|
response = get_response(uri)
|
52
|
-
if response.is_a? Net::HTTPSuccess
|
53
|
-
|
47
|
+
if response.is_a? Net::HTTPSuccess and response.body =~ /Sitemap:\s*(.*)/
|
48
|
+
check_sitemap($1)
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
|
-
def
|
58
|
-
@logger.debug "checking
|
59
|
-
uri = URI.parse(
|
60
|
-
uri.path = '/sitemap.xml.gz'
|
52
|
+
def check_sitemap(url)
|
53
|
+
@logger.debug "checking #{url} file" if @logger
|
54
|
+
uri = URI.parse(url)
|
61
55
|
response = get_response(uri)
|
62
56
|
if response.is_a? Net::HTTPSuccess
|
63
|
-
|
64
|
-
|
57
|
+
body = url =~ /gz$/ ? Zlib::GzipReader.new(StringIO.new(response.body)).read : response.body
|
58
|
+
if body.index "<sitemap>"
|
59
|
+
sitemap_locs = body.scan(%r{<loc>(.*?)</loc>}).flatten
|
60
|
+
sitemap_locs.each { |loc| check_sitemap(loc) }
|
61
|
+
else
|
62
|
+
@locations = body.scan(%r{<loc>(.*?)</loc>}).flatten
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
data/seo_checker.gemspec
CHANGED