kpumuk / meta-tags

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

Double separator for .meta_title method on #145

Closed rsiddle closed 7 years ago

rsiddle commented 7 years ago

Using version 2.6.0

# application.html.erb
<%= display_meta_tags site: 'My website', reverse: true, prefix: false %>
# pages/show.html.erb
<% set_meta_tags(
  title: @page.meta_title,
  description: @page.meta_description,
)%>

The output is:

<title>Testing meta title here || My website</title>

If I change to use @page.title, it seems to work fine.

<% set_meta_tags(
  title: @page.title,
  description: @page.meta_description,
)%>

The output is:

<title>Test | My website</title>

@page.meta_title returns "Overriding the title | Example Site"

I would expect this to output "Overriding the title | Example Site | My website"

It appears as though the string is being sanitized and removes everything past the pipe | character. I see title can accept an Array so it automatically adds the separator if needs be. It seems like odd behaviour to strip past the pipe/separator in a string though.

kpumuk commented 7 years ago

Hey. MetaTags does not strip any characters if they fit into the limit (70 characters by default). Could you add something like

<pre><%= @page.meta_title.inspect %></pre>

to your page and post the result here for me to reproduce/investigate?

kpumuk commented 7 years ago

Tried:

set_meta_tags(
  title: 'Overriding the title | Example Site',
)
display_meta_tags(
  site: 'My website',
  reverse: true,
)

and it is rendering:

<title>Overriding the title | Example Site | My website</title>
kpumuk commented 7 years ago

The only way to reproduce the issue you're seeing is here:

set_meta_tags(
  title: 'Overriding the title very long title something wtf | Example Site',
)
display_meta_tags(
  site: 'My website',
  prefix: false,
  reverse: true,
)

Renders:

<title>Overriding the title very long title something wtf || My website</title>

This is because the result title is reaching the limit (70 chars), and page title gets truncated. There are two options:

  1. Change title limit to a bigger number (keep in mind that search engines will truncate it to 60-80 chars anyway): config.title_limit
  2. Change the truncation rules to first truncate site title: config.truncate_site_title_first

Global settings file can be generated using rails generate meta_tags:install

kpumuk commented 7 years ago

One small correction: if the string was truncated as is, on the character break, the result would have been Overriding the title very long title something wtf | Exam | My website. But MetaTags tries to break title on word edges, so the truncated word Exam does not appear in the result.

kpumuk commented 7 years ago

@rsiddle hey. could you confirm that the issue is resolved for you? :-)

kpumuk commented 7 years ago

Closing the issue. If you have any more questions - feel free to re-open.