1

我正在使用 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
  • 我将域更改为 localhost

该应用程序托管在 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 lsheroku run rake ls tmp并且heroku run rake ls public无处可寻。

过去,我在 sitemap.rb 上也有这两行:

SitemapGenerator::Sitemap.public_path = 'tmp/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'

但仍然没有在此文件夹上生成站点地图。任何线索我做错了什么并且没有生成?

4

2 回答 2

0

我在这里找到了解决方案。

我不得不使用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>)
于 2016-03-28T11:08:09.073 回答
0

Heroku 没有永久文件系统。因此,heroku 上的任何上传都不是永久性的。查看此文档以获取更多信息 https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

于 2016-03-28T10:25:40.557 回答