Browse files

Bing ping added. Added option for disabling ping.

  • Loading branch information...
1 parent f231337 commit 2b8d22a903b9a1393940873ba2feebed51695286 @christianhellsten committed Aug 7, 2010
View
1 install.rb
@@ -6,6 +6,7 @@
file << "domain: # For example: 'aktagon.com'"
file << "change_frequency: weekly"
file << "limit: 5000"
+ file << "ping: true"
file << "priority: 1.0"
end
end
View
15 lib/sitemap_generator.rb
@@ -10,9 +10,12 @@ module Version #:nodoc:
end
end
-require File.join(RAILS_ROOT, 'config', 'environment')
-require File.join(File.dirname(__FILE__), '/sitemap_generator/active_record')
-require File.join(File.dirname(__FILE__), '/sitemap_generator/generator')
-require File.join(File.dirname(__FILE__), '/sitemap_generator/helpers')
-require File.join(File.dirname(__FILE__), '/sitemap_generator/options')
-require File.join(File.dirname(__FILE__), '/sitemap_generator/sitemap')
+# need this for config.threadsafe!
+if Rails.env == 'production'
+ require File.join(Rails.root, 'config', 'environment')
+ require File.join(File.dirname(__FILE__), '/sitemap_generator/active_record')
+ require File.join(File.dirname(__FILE__), '/sitemap_generator/generator')
+ require File.join(File.dirname(__FILE__), '/sitemap_generator/helpers')
+ require File.join(File.dirname(__FILE__), '/sitemap_generator/options')
+ require File.join(File.dirname(__FILE__), '/sitemap_generator/sitemap')
+end
View
13 lib/sitemap_generator/generator.rb
@@ -110,7 +110,8 @@ def generate(&block)
end
def ping?
- valid? && changed? #&& RAILS_ENV == 'production'
+ return false if !Options.ping # || Rails.env != 'production'
+ valid? && changed?
end
def changed?
@@ -131,10 +132,12 @@ def ping
# Ping sites http://en.wikipedia.org/wiki/Sitemaps
# TODO support other names than sitemap.xml?
- [ "http://www.google.com/webmasters/tools/ping?sitemap=http://#{Options.domain}/sitemap.xml",
- "http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://#{Options.domain}/sitemap.xml",
- "http://submissions.ask.com/ping?sitemap=http://#{Options.domain}/sitemap.xml",
- "http://webmaster.live.com/ping.aspx?siteMap=http://#{Options.domain}/sitemap.xml" ].each do |url|
+ sitemap = "http://#{Options.domain}/sitemap.xml"
+
+ [ "http://www.google.com/webmasters/tools/ping?sitemap=#{sitemap}",
+ "http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=#{sitemap}",
+ "http://submissions.ask.com/ping?sitemap=#{sitemap}",
+ "http://www.bing.com/webmaster/ping.aspx?siteMap=#{sitemap}" ].each do |url|
open(url) do |f|
if f.status[0] == "200"
p "Sitemap successfully submitted to #{url}"
View
1 test/rails_app/config/sitemap.yml
@@ -1,5 +1,6 @@
domain: aktagon.com
limit: 5000
+ping: true
priority: 1
change_frequency: weekly
View
14 test/sitemap_generator_test.rb
@@ -50,13 +50,21 @@ class SitemapGeneratorTest < Test::Unit::TestCase
urls = [
'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://aktagon.com/sitemap.xml',
'http://www.google.com/webmasters/tools/ping?sitemap=http://aktagon.com/sitemap.xml',
- 'http://submissions.ask.com/ping?sitemap=http://aktagon.com/sitemap.xml',
- 'http://webmaster.live.com/ping.aspx?siteMap=http://aktagon.com/sitemap.xml'
+ 'http://www.bing.com/webmaster/ping.aspx?siteMap=http://aktagon.com/sitemap.xml',
+ 'http://submissions.ask.com/ping?sitemap=http://aktagon.com/sitemap.xml'
].each do |url|
FakeWeb.register_uri(:get, url, :body => "")
end
- generator = SitemapGenerator::Generator.new.ping
+ generator = SitemapGenerator::Generator.new
+ generator.ping
+ end
+
+ should "should not ping if ping is disabled" do
+ generator = SitemapGenerator::Generator.new
+ generator.ping?.should == true
+ mock(SitemapGenerator::Options).ping.returns(false)
+ generator.ping?.should == false
end
end
end

0 comments on commit 2b8d22a

Please sign in to comment.