Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make ping task independent on generate task

  • Loading branch information...
commit 5cc9e58a70e4dc585b5f6760fd201045f731386b 1 parent 84cd4b6
@flyerhzm authored
Showing with 18 additions and 21 deletions.
  1. +14 −19 lib/sitemap_ping.rb
  2. +4 −2 tasks/sitemap_tasks.rake
View
33 lib/sitemap_ping.rb
@@ -6,29 +6,24 @@ module Sitemap
class SearchEngine
GOOGLE = 'http://www.google.com/webmasters/tools/ping?sitemap='
- BING = 'http://cn.bing.com/webmaster/ping.aspx?siteMap='
+ BING = 'http://com.bing.com/webmaster/ping.aspx?siteMap='
YAHOO = 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='
ASK = 'http://submissions.ask.com/ping?sitemap='
class <<self
- def ping_google
- ping(GOOGLE)
- end
-
- def ping_bing
- ping(BING)
- end
-
- def ping_yahoo
- ping(YAHOO)
- end
-
- def ping_ask
- ping(ASK)
- end
-
- def ping(url)
- Net::HTTP.get_print URI.parse(url + CGI::escape(Sitemap::Routes.host + '/sitemap.xml'))
+ def ping(engine, format)
+ url = case engine
+ when 'google'
+ GOOGLE
+ when 'bing'
+ BING
+ when 'yahoo'
+ YAHOO
+ when 'ask'
+ ASK
+ end
+ sitemap_file = (format == 'gzip' ? '/sitemap.xml.gz' : '/sitemap.xml')
+ Net::HTTP.get_print URI.parse(url + CGI::escape(Sitemap::Routes.host + sitemap_file))
end
end
end
View
6 tasks/sitemap_tasks.rake
@@ -13,10 +13,12 @@ namespace :sitemap do
end
desc "ping search engine to update sitemap.xml (or specify SEARCH_ENGINE=names, splitted by comma)"
- task :ping => :generate do
+ task :ping => :environment do
+ sitemap_configure_file = File.join(RAILS_ROOT, 'config/sitemap.rb')
+ load(sitemap_configure_file)
engines = ENV['SEARCH_ENGINE'].nil? ? %w(google bing yahoo ask) : ENV['SEARCH_ENGINE'].split(',')
engines.each do |engine|
- Sitemap::SearchEngine.send("ping_#{engine}")
+ Sitemap::SearchEngine.send("ping", engine, ENV['FORMAT'] || 'xml')
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.