“Ruby on Rails sitemap plugin”

rails, Uncategorized

I have created a plugin named Dynamic Sitemaps that enables you to easily create flexible, dynamic sitemaps in Ruby on Rails. It generates sitemaps in the sitemaps.org standard which is supported by several crawlers including Google, Bing, and Yahoo. If the sitemap has more than 50.000 urls – or whatever you set it to using per_page – the plugin will automatically split the sitemap into smaller chunks and generate a sitemap index as specified at sitemaps.org.


To install in Rails 3:


rails plugin install git@github.com:lassebunk/dynamic_sitemaps.git


In config/initializers/sitemap.rb:


Sitemap::Map.draw do

  # default page size is 50.000 which is the specified maximum at http://sitemaps.org.
  per_page 10

  url root_url, :last_mod => DateTime.now, :change_freq => 'daily', :priority => 1

  new_page!

  Product.all.each do |product|
    url product_url(product), :last_mod => product.updated_at, :change_freq => 'monthly', :priority => 0.8
  end

  new_page!

  autogenerate  :products, :categories,
                :last_mod => :updated_at,
                :change_freq => 'monthly',
                :priority => 0.8

  new_page!

  autogenerate  :users,
                :last_mod => :updated_at,
                :change_freq => lambda { |user| user.very_active? ? 'weekly' : 'monthly' },
                :priority => 0.5

end


In config/routes.rb:


match 'sitemap' => 'sitemaps#sitemap'


You are now able to access your sitemap at http://yourdomain.com/sitemap.xml.


In public/robots.txt:


Sitemap: http://yourdomain.com/sitemap.xml


And at last submit it to Google, Bing, and Yahoo.


Check out the plugin at GitHub.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s