1
0

More than 3 years have passed since last update.

【SearchConsole】data-vocabulary.orgが非推奨に、パンくずgemのgretelを互換性のあるbuoysに乗り換え

Last updated at Posted at 2020-04-08

railsの超有名gemであるgretelからbuoysに乗り換えました。

railsの言わずと知れたパンくずのgemである、gretelですが現時点(2020/04/08)ではdata-vocabulary.orgを利用しているため
schema.orgを利用している buoys にライブラリを乗り換えました。

乗り換え方法はページ下部に記載。

rails の gretel もそのうち対応されそうです。

現時点では対応されておりませんが。
グレーテルのFork先でPRが作られた、対応される見込みはあるとおもいます。

issueの方でも対応する予定はありますとコメントがありますね。
https://github.com/WilHall/gretel/issues/16

なので今は慌てて対応せずモンキーパッチで対応するのも良いかと思われます。

@yamitake@github 先生の記事が参考になります
https://qiita.com/yamitake@github/items/96a0b0a9036aa345dd62

背景はGoogleの仕様変更

Google は2020年4月6日以降、data-vocabulary.org を検索結果のリッチリザルトの対象外にすることを決めた。

検索順位に影響がでるという情報は見たところないようです。
また、ページとしても引き続き有効という説明がありました。

Googleからのメールには「検索結果での表示に影響がある場合がございます。」とある通り、あくまでも表示に影響が出るだけのようです。

ただし、検索結果での表示に影響があればクリック率にも影響する可能性がありますので、早めに対応することをお勧めします。

対応するメリット

Googleの検索結果に引き続きリッチスニペット表示することができる。
対応しないとリッチスニペットではなくなる

buoysはgretelと互換性のあるgem

明示的に互換性があるとは言っておりませんが、非常に似ているため以降が楽です。

必要な作業は2つ

  • gem を install
  • 初期化コマンドを打つ
  • ファイル名を書き換え

これだけで終わります。

Gemfileに追記

Gemfile
gem 'buoys'
bundle_install
bundle install

初期化コマンド

初期化コマンド
bin/rails g buoys:install

こんなファイルが生まれますので、パンくずを設置していた部分でこれを読み込んでください。

app/views/breadcrumbs/_buoys.html.erb
<% if buoys.any? %>
  <ol itemscope itemtype='http://schema.org/BreadcrumbList' class='breadcrumb'>
    <% buoys.each.with_index(1) do |link, i| %>
      <li itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
        <%# if `link.current?` is true, link.options includes {class: 'current'}. %>
        <% if link.current? %>
          <span itemprop='name'><%= link.text %></span>
          <meta itemprop='position' content='<%= i %>' />
        <% else %>
          <%= link_to link.url, link.options.merge(itemprop: :item) do %>
            <span itemprop='name'><%= link.text %></span>
          <% end %>
          <meta itemprop='position' content='<%= i %>' />
        <% end %>
      </li>
    <% end %>
  </ol>
<% end %>
gretelの読み込み部分を
== breadcrumbs(semantic: true, separator: nil)
こんな感じに変更する
= render('breadcrumbs/buoys')

ファイルの移動

パンくずの設定ファイルを移動します(内容の変更は不要です)

config/breadcrumbs/article/hoge.rb → config/buoys/article/hoge.rb

終わり

スタイル崩れがあったら、CSSのクラス名などを調整してあげて完成です
1日あれば移行できてしまいますね

image.png

1
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
1
0