LoginSignup
13
11

More than 5 years have passed since last update.

Ruby On Rails sitemap_generaterを使ってサイトマップの作成

Posted at

GEMのインストール

gem 'sitemap_generator'

設定ファイルの生成

rake sitemap:install

これでconfig/sitemap.rbが生成されるのでサイトマップに登録するURLを記載していきます

設定例

サイトマップの設定方法はドキュメントにだいたい全て書いてあります。
kjvarga/sitemap_generator
https://github.com/kjvarga/sitemap_generator#sitemap-configuration

config/sitemap.rb
# Set the host name for URL creation
# Defaults: :priority => 0.5, :changefreq => 'weekly',
#           :lastmod => Time.now, :host => default_host

SitemapGenerator::Sitemap.default_host = "http://www.pla-cole.wedding"

SitemapGenerator::Sitemap.create do
  current_time = Time.now

  # トップ画面
  add root_path, lastmod: current_time, changefreq: 'daily', priority: 1.0

  # 静的ページ
  static_page_options = { lastmod: current_time, changefreq: 'monthly', priority: 0.5 }
  add(sign_in_path, static_page_options)
  add(sign_up_path, static_page_options)
  add(policy_path, static_page_options)
  add(guide_path, static_page_options)
  add(faq_path, static_page_options)


  # 動的ページ
  dynamic_page_options = { changefreq: 'weekly', priority: 0.75 }

  # Hogeモデル詳細画面
  Hoge.only_opened.find_each do | hoge |
    add(hoge_path(hoge.id), dynamic_page_options.merge(lastmod: hoge.updated_at))
  end

  # Fuga詳細画面
  Fuga.find_each do | fuga |
    add(fuga_path(hall.id), dynamic_page_options.merge(lastmod: hall.updated_at))
  end
end

XMLファイルの生成

./bin/rake sitemap:refresh
# 通知を行いたくない場合は下記
./bin/rake sitemap:refresh:no_ping

参考

【Ruby, Rails】sitemap-generatorを使ってsitemapを作成。
http://shirusu-ni-tarazu.hatenablog.jp/entry/2012/10/09/013117

sitemap.xmlの記載方法と書式、設置する事で得られるメリット
http://holy-seo.net/blog/seo/sitemap-sml-method-described-merit/

meta-tagsとsitemap_generatorで始めるRails 4.1時代のSEO対策
http://morizyun.github.io/blog/meta-tags-sitemap-generator-rails-seo/

Railsでサイトマップ(sitemap.xml)を作りたい
http://code.materializer.co/20

サイトマップのSEO効果と理想的な作成方法
http://bazubu.com/how-to-create-an-effective-site-map-26793.html

13
11
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
13
11