route.rb
get 'sitemap', to: redirect('https://s3-ap-northeast-1.amazonaws.com/バケット名/sitemaps/sitemap.xml.gz')
sitemap.rb
SitemapGenerator::Sitemap.default_host = "サイトのurl"
SitemapGenerator::Sitemap.sitemaps_host = "https://s3-ap-northeast-1.amazonaws.com/#{ENV['S3_BUCKET_NAME']}"
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AwsSdkAdapter.new(
ENV['S3_BUCKET_NAME'],
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
aws_region: 'ap-northeast-1'
)
SitemapGenerator::Sitemap.create do
add posts_path, changefreq: 'daily'
posts = Post.published
posts.find_each do |post|
add post_path(post), lastmod: post.updated_at
end
end
herokuに環境変数を設定する。
search console
ドメイン/sitemapで登録