LoginSignup
0
0

More than 3 years have passed since last update.

railsサイトマップをサーチコンソールに送る方法

Posted at

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で登録

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0