Google sitemap files for Rails projects

后端 未结 6 1973
情深已故
情深已故 2020-12-07 08:13

Is there an easy way to create a sitemaps file for Rails projects? Especially for dynamic sites (such as Stack Overflow for example) there should be a way to dynamically cre

6条回答
  •  鱼传尺愫
    2020-12-07 08:54

    Here is a plugin for creating sitemaps in Ruby on Rails: Ruby on Rails sitemap plugin. It takes care of most of the sitemap logic and generation. The plugin is from my homepage.

    Example configuration:

    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
    

    Best regards, Lasse

提交回复
热议问题