创建生产链接的站点地图?

Create Sitemap of Production Links?

站点地图存储了我在开发中创建的链接。如何从生产中获取链接?

$ rake sitemap:create

In '/Users/galli01anthony/Dropbox/LiveToChallenge/public/sitemaps/':
+ sitemap.xml.gz                                         133 links /    2.09 KB
Sitemap stats: 133 links / 1 sitemaps / 0m02s

Pinging with URL 'http://www.livetochallenge.com/sitemap.xml.gz':
  Successful ping of Google
  Successful ping of Bing

default_host 是正确的,但它显示像 http://www.livetochallenge.com/challenges/19-test, which doesn't exist in production. http://0.0.0.0:3000/challenges/19-test 这样的链接只存在于开发中。

sitemap.rb

SitemapGenerator::Sitemap.default_host = 'http://www.livetochallenge.com/'
SitemapGenerator::Sitemap.public_path = 'public/sitemaps/'

SitemapGenerator::Sitemap.create do
  add posts_path, changefreq: 'daily'
  add challenges_path, changefreq: 'daily'
  add inspirations_path, changefreq: 'weekly'
  add users_path, changefreq: 'weekly'
  add activities_path, changefreq: 'weekly'
  add about_path, changefreq: 'monthly'
  Post.find_each do |f|
    add post_path(f.slug), lastmod: f.updated_at
  end
  Challenge.find_each do |f|
    add challenge_path(f), lastmod: f.updated_at
  end
  Inspiration.find_each do |f|
    add inspiration_path(f), lastmod: f.updated_at
  end
  User.find_each do |f|
    add user_path(f), lastmod: f.updated_at
  end
end

SitemapGenerator::Sitemap.ping_search_engines

您似乎是 运行 开发环境中的 rake 任务,因此它正在从您的开发数据库中提取记录。确保您的 ENV 设置为生产环境:RAILS_ENV=production bundle exec rake sitemap:create 并且您能够连接到您的生产数据库。