# Set the host name for URL creation
# Not sitemap.xml.gz but sitemap.xml
SitemapGenerator::Sitemap.compress = false
SitemapGenerator::Sitemap.default_host = "https://www.example.com"
SitemapGenerator::Sitemap.create do
# Put links creation logic here.
#
# The root path '/' and sitemap index file are added automatically for you.
# Links are added to the Sitemap in the order they are specified.
#
# Usage: add(path, options={})
# (default options are used if you don't specify)
#
# Defaults: :priority => 0.5, :changefreq => 'weekly',
# :lastmod => Time.now, :host => default_host
#
# Examples:
#
# Add '/articles'
#
# add articles_path, :priority => 0.7, :changefreq => 'daily'
#
# Add all articles:
#
# Article.find_each do |article|
# add article_path(article), :lastmod => article.updated_at
# end
add "/", :changefreq => "daily", :priority => 0.9
Post.find_each do |item|
add post_path(item.slug, format: :html), :lastmod => item.updated_at, priority: 0.8, changefreq: "daily"
end
ActsAsTaggableOn::Tag.find_each do |item|
add "/tags/#{item.id}.html", :lastmod => item.updated_at, priority: 0.7, changefreq: 'daily'
end
Category.find_each do |item|
add category_path(item.slug, format: :html), :lastmod => item.updated_at, priority: 0.2, changefreq: "monthly"
end
end
添加每天的定时任务 config/schedule.rb
# sitemap
every 1.day, :at => '3:00 am' do
rake 'rake sitemap:refresh', :environment => ENV['RAILS_ENV'] || 'development'
end