kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Open Graph og:site_name getting merged with title #119

Closed brentdodell closed 7 years ago

brentdodell commented 8 years ago

I have the following:

site: 'Site Name',
title: 'Page Name',
reverse: true,
og: {
  site_name: :site,
  title: :title,
  description: :description,
  url: :canonical
}

Which results in the following HTML:

<title>Page Name | Site Name</title>
<meta content="My description" name="description">
<link href="http://mydomain.com/the/rest/of/the/url" rel="canonical">

<meta content="Page Name | Site Name" property="og:title">
<meta content="My description" property="og:description">
<meta content="http://mydomain.com/the/rest/of/the/url" property="og:url">

As far as the og: tags are concerned, they should be the following:

<meta content="Site Name" property="og:site_name">
<meta content="Page Name" property="og:title">
<meta content="My description" property="og:description">
<meta content="http://mydomain.com/the/rest/of/the/url" property="og:url">

I believe it is a bug that og:title is :title | :site. According to Open Graph's Basic tags, there should be separate og:site_name and og:title tags. Also, on that same page it mentions fb:app_id as one of the basic Open Graph tags. I believe this gem has issues with that as well (see issue #118).

Thanks for a great gem overall!

detonatR commented 8 years ago

having this issue too, did you manage to get a work around going?

jakebellacera commented 7 years ago

:+1:

any forks with this solved already?

kuboon commented 7 years ago

I wrote monky patch for this issue. Add this to config/initializers/meta_tags.rb

module MetaTags
  class Renderer
    def render_title(tags)
      site       = meta_tags.extract(:site) || ''
      title      = meta_tags.extract_title || []
      separator  = meta_tags.extract_separator
      reverse    = meta_tags.extract(:reverse) === true

      normalized_meta_tags[:site]  = site
      normalized_meta_tags[:title] = TextNormalizer.normalize_title('', title, separator, reverse)

      site_title = TextNormalizer.normalize_title(site, title, separator, reverse)
      normalized_meta_tags[:site_title] = site_title
      tags << ContentTag.new(:title, content: site_title) if site_title.present?
    end
  end
end

normalized_meta_tags is a hash which is referred by symbol like :title. Unfortunately extract_full_title removes title from hash and keeps it to nowhere, I didn't use the function.