Arjan van der Gaag

By Arjan van der Gaag on Jun 10 2009.
Tagged ruby, rake, google, ping, automation, blog, blogging, script.

← back to all talks and articles

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

Running 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 my entire Rakefile at Github.

  • ruby
  • rake
  • google
  • ping
  • automation
  • blog
  • blogging
  • script
Arjan van der Gaag

Arjan van der Gaag

A thirtysomething software developer, historian and all-round geek. This is his blog about Ruby, Rails, Javascript, Git, CSS, software and the web. Back to all talks and articles?

Discuss

You cannot leave comments on my site, but you can always tweet questions or comments at me: @avdgaag.