当区域设置不同时,Facebook将忽略og:url标记

时间:2019-05-16 15:39:22

标签: html ruby-on-rails facebook-opengraph opengraph

我有两种不同语言(en和fr)的Rails应用程序。当我放入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 %>

为什么在尝试获取French meta标签时,facebook抓取工具说没有og:url和og:description或抓错了?为什么不遵循正确的重定向?我错过了什么还是做错了什么?

谢谢!

0 个答案:

没有答案