1

I am using the sitemap_generator gem and have the following configuration at 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
  • I changed my domain to localhost

The app is hosted on heroku. When I do a heroku run rake sitemap:refresh I get the following results

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

Now I try to find the sitemap.xml.gz file and its nowhere on heroku. I do a heroku run rake ls, heroku run rake ls tmp and heroku run rake ls public and is nowhere to be found.

In the past I had these two lines on sitemap.rb as well:

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

but still the sitemaps were not generated on this folders. Any clue what I am doing wrong and is not generated?

2 Answers2

0

Heroku doesn't have permanent filesystem. So any uploads on heroku isn't permanent.Check this documentation for more info https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

sureshprasanna70
  • 1,043
  • 1
  • 10
  • 27
0

I found the solution here.

I had to use the fog-aws gem and configure the sitemap.rb file:

# 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/'

Don't forget to setup the adapter environment variables:

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>)
  • I have similar setup and when I visit /sitemap the file is being downloaded, but still have no idea why some seo analyzers tell me: no sitemap.xml (https://app.neilpatel.com/en/seo_analyzer) – rtrojanowski Jun 26 '19 at 09:08