Dynamic Sitemaps 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
Generate initializer and route:
$ rails generate dynamic_sitemaps sitemap.xml
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
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.
If you want to notify search engines with changes to your sitemap, see the Sitemap Notifier plugin.
Related posts
Tags: Bing, Generator, Google, Plugins, Ruby on Rails, Sitemaps, Yahoo
[...] of changes to your models, i.e. changes to your sitemap. It also works in conjunction with the Dynamic Sitemaps [...]
Hi, you use initializers to create a sitemap, it is really really not friendly for development (I have to restart rails server),
consider change to other ways?
Hi halida,
You’re right! I’ll try to fix this in a future version – good idea.
Regards,
Lasse