Rake task to ping Google
Creating and publishing a sitemap XML file helps search engines find and index all of your content. Most CMS alert Google to come check out your sitemap file, but here’s a Rake task to do it yourself.
This site is generated using Jekyll, a static website generator. I’ve got a sitemap file set up to include links to all my pages and posts. All I need now is to tell Google the file has changed – and do that every time I push changes to my server.
Rake to the rescue
I’ve set up the following Rake task to handle pinging Google for me:
desc 'Notify Google of the new sitemap' task :sitemap do require 'net/http' require 'uri' Net::HTTP.get( 'www.google.com', '/webmasters/tools/ping?sitemap=' + URI.escape('http://domain.com/sitemap.xml') ) end end
rake sitemap is now enough to let Google know that my sitemap has
changed. I have chained this task in my publication process, so that every
time I run
rake publish my site will be re-generated and published, and
Google will be notified.
I’ve also set up a task to ping ping-o-matic. You see
Rakefile at Github.