Arjan van der Gaag .nl

I’m Arjan van der Gaag and this is my website about me, code, food, photography and more. If you like, we can get in touch.


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.