我使用的是sitemap_generator gem,并在config / sitemap.rb中进行了以下配置:
require 'rubygems'
require 'sitemap_generator'
SitemapGenerator::Sitemap.default_host = 'http://www.localhost.com'
SitemapGenerator::Sitemap.create do
add '/', :changefreq => 'daily', :priority => 0.9
add '/contact', :changefreq => 'weekly'
User.find_each do |user|
add users_path(user), lastmod: user.updated_at
end
end
SitemapGenerator::Sitemap.ping_search_engines
该应用程序托管在heroku上。当我做heroku run rake sitemap:refresh
时,我得到以下结果
In '/app/public/':
+ sitemap.xml.gz 76 links / 1.53 KB
Sitemap stats: 76 links / 1 sitemaps / 0m00s
Pinging with URL 'http://www.localhost.com/sitemap.xml.gz':
Successful ping of Google
Successful ping of Bing
Pinging with URL 'http://www.localhost.com/sitemap.xml.gz':
Successful ping of Google
Successful ping of Bing
现在我尝试在heroku上找到sitemap.xml.gz文件并且无处可寻。我做了heroku run rake ls
,heroku run rake ls tmp
和heroku run rake ls public
,无处可寻。
过去我在sitemap.rb上也有这两行:
SitemapGenerator::Sitemap.public_path = 'tmp/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
但仍未在此文件夹上生成站点地图。我知道我做错了什么并且没有生成?
答案 0 :(得分:0)
Heroku没有永久文件系统。所以在heroku上的任何上传都不是永久性的。请查看此文档以获取更多信息 https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
答案 1 :(得分:0)
我找到了解决方案here。
我必须使用fog-aws gem并配置sitemap.rb文件:
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://example.com"
# pick a place safe to write the files
SitemapGenerator::Sitemap.public_path = 'tmp/'
# store on S3 using Fog (pass in configuration values as shown above if needed)
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new
# inform the map cross-linking where to find the other maps
SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com/"
# pick a namespace within your bucket to organize your maps
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
不要忘记设置适配器环境变量:
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(fog_provider: 'AWS',
aws_access_key_id: <your-access-key-id>,
aws_secret_access_key: <your-access-key>,
fog_directory: <your-bucket>,
fog_region: <your-aws-region e.g. us-west-2>)