Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created April 16, 2015 20:56
Show Gist options
  • Select an option

  • Save ahoward/c5f9cec980ce7d4906c7 to your computer and use it in GitHub Desktop.

Select an option

Save ahoward/c5f9cec980ce7d4906c7 to your computer and use it in GitHub Desktop.
og: tags should be a first class citizen of any web site or application. sharing urls is part of the web today #FYI
<%
@layout.default.title = "Titile"
@layout.default.description = "Description"
@layout.default.author = "Author"
@layout.default.keywords = %w[ foo bar baz ]
@layout.default.image = App.url(image_path("og.png"))
if @content
begin
#
@layout.default.title =
@content.title
#
@layout.default.description =
@content.excerpt || @content.auto_excerpt
#
keywords =
Coerce.list_of_strings %w[ keywords tags category ].map{|key| @content[key]}
if keywords.present?
@layout.default.keywords = keywords
end
#
case
when @content.respond_to?(:banner_url)
@layout.default.image = @content.banner_url
else
if((image = @content.assets.detect{|asset| asset.image?}))
@layout.default.image = image.url(:medium)
end
end
rescue => e
Rails.logger.error(e)
end
end
@layout.default.og = {
:type => proc{ "website" },
:site_name => proc{ "Site Name" },
:title => proc{ @layout.title },
:description => proc{ @layout.description },
:image => proc{ @layout.image }
}
%>
<html>
<head>
<%= og @layout.og %>
</head>
</html>
def og(*args, &block)
options = Map.options_for(args)
tagz {
options.each do |name, content|
name = name.to_s
unless name =~ /^og:/
name = "og:#{ name }"
end
meta_(:property => name, :content => content)
__
end
}.html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment