Awesome
Sitemap Notifier
Sitemap Notifier is a Ruby on Rails plugin that, when installed, automatically notifies Google, Bing, and Yahoo of changes to your models, i.e. changes to your sitemap. It also works in conjunction with the dynamic_sitemaps plugin.
Installation
In your Gemfile:
gem 'sitemap_notifier'
And run:
$ bundle install
Example
Start by generating an initializer:
$ rails generate sitemap_notifier:install
Then, in config/initializers/sitemap_notifier.rb:
SitemapNotifier::Notifier.configure do |config|
# Set URL to your sitemap. This is required.
# This can also be configured per model basis,
# see https://github.com/lassebunk/sitemap_notifier#per-model-sitemap-url
config.sitemap_url = "http://example.com/sitemap.xml"
# Models that should trigger notification of search engines.
# Default is to trigger on all creates, updates, and deletes.
config.models = [Article, Category]
# Or, if you want to specify on which actions to notify search engines:
config.models = { Article => [:create, :destroy],
Product => :update,
Page => :all }
# Enabled in which environments – default is [:production]
config.environments = [:development, :production]
# Delay to wait between notifications – default is 10 minutes
config.delay = 2.minutes
# Additional urls to ping
config.ping_urls << "http://localhost:3000/ping?sitemap=%{sitemap_url}"
end
Then create or update a model:
Article.create :title => "My New Article"
The search engines are then automatically notified.
After installation
After you install and configure the plugin, it'll automatically notify Google, Bing, and Yahoo every time you update a model. After each notification, it'll wait 10 minutes (by default) before notifying again. This is to ensure that for example a batch update won't trigger an equal amount of notifications.
Customization
Per model sitemap URL
The sitemaps defaults to what you set in SitemapNotifier::Notifier.sitemap_url
. If you want to use a different sitemap URL based on data in your models, you can override the sitemap_url
method of each of your models like this:
class Product < ActiveRecord::Base
belongs_to :site
def sitemap_url
"http://#{site.domain}/sitemap.xml"
end
end
Conditional notifications
You can decide on model level whether the search engines should be pinged by overriding the notify_sitemap?
method of your models:
class Product < ActiveRecord::Base
belongs_to :site
def notify_sitemap?
site.id == 1
end
end
Documentation
Versioning
Follows semantic versioning.
Copyright © 2010-2013 Lasse Bunk, released under the MIT license