Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raveman/df48bc0e4e8cdbabf66b2deef5eb2212 to your computer and use it in GitHub Desktop.
Save raveman/df48bc0e4e8cdbabf66b2deef5eb2212 to your computer and use it in GitHub Desktop.
social meta tags helper ruby on rails 4
def social_meta_tags
title = "#{(content_for?(:title) ? (strip_tags(content_for(:title)).html_safe + ' / ') : '')}#{t('project_title')}"
description = content_for?(:description) ? content_for(:description) : ''
image = if @doc.present?
image_url(@doc.cover_photo.cover.url)
elsif @main.present?
image_url(@main.cover_photo.cover.url)
else
''
end
content_tag(:title, title) +
content_tag(:meta, nil, content: title, property: 'og:title') +
content_tag(:meta, nil, content: description, property: 'og:description') +
content_tag(:meta, nil, content: "#{request.original_url}?title=#{title}", property: 'og:url') +
content_tag(:meta, nil, content: image, property: 'og:image') +
content_tag(:meta, nil, content: title, name: 'title') +
content_tag(:meta, nil, content: description, name: 'description') +
content_tag(:link, nil, href: image, rel: 'image_src').html_safe +
content_tag(:meta, nil, content: 'twitter summary', name: 'twitter:card') +
content_tag(:meta, nil, content: title, name: 'twitter:title') +
content_tag(:meta, nil, content: description, name: 'twitter:description') +
content_tag(:meta, nil, content: image, name: 'twitter:image') +
content_tag(:meta, nil, content: title, itemprop: 'name') +
content_tag(:meta, nil, content: description, itemprop: 'description') +
content_tag(:meta, nil, content: image, itemprop: 'image')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment