The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Google Sitemaps Rails plugin

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rodney ramdas

Posts: 66
Nickname: pinupgeek
Registered: Jun, 2006

Rodney Ramdas is a de-enterprised Ruby on Rails developer from the Netherlands.
Google Sitemaps Rails plugin Posted: Nov 7, 2006 4:07 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rodney ramdas.
Original Post: Google Sitemaps Rails plugin
Feed Title: pinupgeek.com
Feed URL: http://feeds.feedburner.com/pinupgeek
Feed Description: A personal take on Ruby and Rails
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rodney ramdas
Latest Posts From pinupgeek.com

Advertisement

I was creating a Google Sitemaps implementation for a customer when it occurred to me sitemaps probably can be put in a nice plugin as long as we follow some conventions. Luckily REST gave us those conventions and so here is the sitemap_generator plugin:

 script/generate sitemap jobs daily

will generate a jobs/sitemap.xml for you:

xml.instruct!
xml.urlset "xmlns" => "http://www.google.com/schemas/sitemap/0.84" do
  xml.url do
    xml.loc         "http://#{@host}/jobs"
    xml.lastmod     w3c_date(@jobs.first.updated_at)
    xml.changefreq  "daily"
  end
  @jobs.each do |job|
    xml.url do
      xml.loc         "http://#{@host}/jobs/#{job.id}"
      xml.lastmod     w3c_date(job.updated_at)
      xml.changefreq  "daily"
    end
  end
end

That builder template results in something like this:


wget http://localhost:3000/jobs/sitemap.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
  <url>
    <loc>http://localhost:3000/jobs</loc>
    <lastmod>2006-11-07T11:31:57+00:00</lastmod>
    <changefreq>daily</changefreq>
  </url>
  <url>
    <loc>http://localhost:3000/jobs/1</loc>
    <lastmod>2006-11-07T11:31:57+00:00</lastmod>
    <changefreq>daily</changefreq>
  </url>
</urlset>

In more general form:

script/generate sitemap <restful_controller_name> <frequency>

Valid frequencies are specified by Google. Be sure to look through the specs. Apart from the above, it also generates a Google SitemapIndex file for you in /sitemap.xml (i.e the file that lists all your sitemaps).

It works because if you’re using REST the plugin can make some assumptions about how your app is structured. I think in 90% of the cases this sitemap_generator is all you’re going to need.

For the rest you’re on your own but you can use the generator as a nice startup since it gives you all the necessary ingredients.

Incidentally, my customer’s wishes we’re a bit more exotic than this plugin could deliver so I didn’t end up using this plugin. But it would be a shame to toss it out the window really so here it is:

svn co svn://www.buildless.com/svn/repos/sitemap_generator

in your vendor/plugins directory and follow the instructions. Feedback is more than welcome.

Read: Google Sitemaps Rails plugin

Topic: Simple and Easy Example With Spring and Ruby Previous Topic   Next Topic Topic: Misc Programs written in Ruby

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use