Facebook игнорирует тег og: url, когда локаль отличается - PullRequest
0 голосов
/ 16 мая 2019

У меня есть приложение rails на 2 разных языках (en и fr). Когда я вставляю отладчик для совместного использования в Facebook, я не получаю нужные og на соответствующем языке.

Когда я получаю английскую версию https://www.mywebsite.ca/en/blogs/soundtracks-for-summer-2019 Я получаю правильные метатеги:

<meta property="og:type" content="website" />
<meta property="og:locale" content="en_CA" />
<meta property="og:locale:alternate" content="fr_CA" />
<meta property="og:title" content="Soundtracks for Summer 2019 | Blogs | My Website" />
<meta property="og:image" content="https://www.mywebsite.ca/blogs/large_iStock.jpg" />
<meta property="og:description" content="Whetever...." />
<meta name="description" content="Whatever..." />
<meta name="url" content="https://www.mywebsite.ca/en/blogs/soundtracks-for-summer-2019" />
<meta property="og:url" content="https://www.mywebsite.ca/en/blogs/soundtracks-for-summer-2019" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

Однако, если я попробую французскую версию https://www.mywebsite.ca/fr/blogs/la-musique-de-votre-ete-2019, я получу:

<meta property="og:type" content="website" />
<meta property="og:locale" content="en_CA" />
<meta property="og:locale:alternate" content="fr_CA" />
<meta property="og:title" content="Blogs | My Website" />
<meta property="og:image" content="https://www.mywebsite.ca/blogs/large_iStock.jpg" />
<meta name="description" content="Blogs description." />
<meta name="url" content="https://www.mywebsite.ca/en/blogs" />
<meta property="og:url" content="https://www.mywebsite.ca/en/blogs" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

Applicaiton.html.erb выглядит так

<meta property="og:type" content="website">
<meta property="og:locale" content="<%= "#{current_locale}_CA" %>">
<% I18n.available_locales.each do |locale| %>
  <% if locale.to_s != current_locale %>
    <meta property="og:locale:alternate" content="<%= "#{locale.to_s}_CA" %>" />
  <% end %>
<% end %>

<% if content_for?(:meta_data) %>
  <%= yield :meta_data %>
<% else %>
  <meta property="og:title" content="<%= "#{yield(:title)} #{t('frontend.website_name')}".html_safe %>">
  <meta property="og:image" content="<%= asset_url("/og/about.jpg") %>">
  <meta property="og:description" content="<%= tags_strip(@description) %>">
  <meta name="description" content="<%= tags_strip(@description) %>">
<% end %>
<link rel="canonical" href="<%= request.original_url %>">

<meta name="url" content="<%= request.original_url %>">
<meta property="og:url" content="<%= request.original_url %>">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<%= yield :alternate_lang %>

blog_details.html.erb выглядит как

<% content_for :alternate_lang do %>
  <% I18n.available_locales.each do |locale| %>
    <% lang = locale.to_s %>
    <% url = sblog_details_url(slug: @blog.slug(lang), locale: lang) %>
    <%= ("<link href='#{url}' rel=alternate hreflang=#{lang}>").html_safe %>
  <% end %>
<% end %>

<% content_for :meta_data do %>
  <% _image = @blog.image %>
  <meta property="og:title" content="<%= "#{@blog.title} | #{t("frontend.menu.blogs")} | #{t('frontend.website_name')}" %>">
  <meta property="og:image" content="<%= asset_url _image.large unless _image.blank? %>">
  <meta property="og:description" content="<%= tags_strip(@blog.description) %>">
  <meta name="description" content="<%= tags_strip(@blog.description) %>">
<% end %>

Почему, пытаясь получить французские метатеги, скребок в фейсбуке говорит, что нет описания og: url и og: или захватывает неправильный? И почему он не следует правильным перенаправлениям? Я что-то упустил или делаю что-то не так?

Спасибо!

...