Last active
August 10, 2021 17:00
-
-
Save stereodenis/d5749a0f17b1b53b5963 to your computer and use it in GitHub Desktop.
social meta tags helper ruby on rails 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
content_tag will do this
<meta></meta>