Sitemap
A simple ruby on rails sitemap generator.
Instalation
Install the gem:
gem install sitemapOr as a plugin:
rails plugin install git://github.com/viseztrance/rails-sitemap.gitThen create the initial config file:
rails g sitemap:installUsage
In your sitemap config file, paths can be indexed as follows:
Sitemap::Generator.instance.load :host => "mywebsite.com" do
path :root, :priority => 1
path :faq, :priority => 0.5, :change_frequency => "weekly"
literal "/my_blog" #helpful for vanity urls layering search results
resources :activities, :params => { :format => "html" }
resources :articles, :objects => proc { Article.published }
# example of added ResourceSync metadata elements
literal "/files/6t053f96k" metadata: { hash: "md5:1584abdf8ebdc9802ac0c6a7402c03b6", length: "8876", type: "text/html" }
endPlease read the docs for a more comprehensive list of options.
Building the sitemap:
rake sitemap:generateBy default the sitemap gets saved in the current application root path. You can change the save path by passing a LOCATION environment variable or using a configuration option:
Sitemap.configure do |config|
config.save_path = "/home/user/apps/my-app/shared"
endPing search engines:
rake sitemap:pingSetting defaults
You may change the defaults for either params or search options as follows:
Sitemap.configure do |config|
config.params_format = "html"
config.search_change_frequency = "monthly"
endLarge sites
Google imposes a limit of 50000 entries per sitemap and maximum size of 10 MB. To comply with these rules, sitemaps having over 10.000 urls are being split into multiple files. You can change this value by overriding the max urls value:
Sitemap.configure do |config|
config.max_urls = 50000
endTests
This project is using minitest. To run the test simply run rake
License
This package is licensed under the MIT license and/or the Creative Commons Attribution-ShareAlike.