seo_checker 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/seo_checker.rb +19 -20
  3. data/seo_checker.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.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
- check_sitemap
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 check_sitemap
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 = '/sitemap.xml'
45
+ uri.path = '/robots.txt'
51
46
  response = get_response(uri)
52
- if response.is_a? Net::HTTPSuccess
53
- @locations = response.body.scan(%r{<loc>(.*?)</loc>}).flatten
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 check_gzip_sitemap
58
- @logger.debug "checking sitemap.xml.gz file" if @logger
59
- uri = URI.parse(@url)
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
- body_io = StringIO.new(response.body)
64
- @locations = Zlib::GzipReader.new(body_io).read.scan(%r{<loc>(.*?)</loc>}).flatten
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{seo_checker}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang