Dynamic Sitemaps is a plugin for Ruby on Rails that enables you to easily create flexible, dynamic sitemaps. It creates 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, also specified at sitemaps.org.
In your Gemfile:
gem 'dynamic_sitemaps'
Then run bundle install
.
Start by generating initializer and route:
$ rails generate dynamic_sitemaps sitemap
In config/initializers/sitemap.rb
:
DynamicSitemaps::Sitemap.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
Then go to yourdomain.com/sitemap.xml in your browser.
In public/robots.txt
:
Sitemap: http://yourdomain.com/sitemap.xml
This will enable crawlers to find your sitemap.
-
Go to Google Webmaster Central at www.google.com/webmasters/ and sign in
-
Click “Add a site…” and follow instructions for adding your site and verify ownership
-
Go to Site configuration > Sitemaps and click “Submit a Sitemap”
-
Type in sitemap.xml – no domain is needed as this is locked to your current website
-
Click “Submit Sitemap”
Google will now download and use your sitemap.
Go to Webmaster Tools at www.bing.com/toolbox/webmasters/ and follow instructions.
Go to Site Explorer at siteexplorer.search.yahoo.com/ and follow instructions.
If you want to notify search engines with changes to your sitemap, see the Sitemap Notifier (github.com/lassebunk/sitemap_notifier) plugin.
-
Lasse Bunk (creator)
-
Aubrey Goodman
Copyright © 2010-2011 Lasse Bunk, released under the MIT license