Skip to content

Commit

Permalink
hella open graph tags
Browse files Browse the repository at this point in the history
added some basic open graph tags to the posts#show page.
  • Loading branch information
maxwell committed Apr 20, 2012
1 parent d0b7833 commit 307ee15
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
38 changes: 38 additions & 0 deletions app/helpers/open_graph_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,38 @@
module OpenGraphHelper
def og_title(post)
meta_tag_with_property('og:title', post_page_title(post))
end

def og_type(post)
meta_tag_with_property('og:type', 'article')
end

def og_url(post)
meta_tag_with_property('og:url', post_url(post))
end

def og_image(post)
if post.photos.present?
img_url = post.photos.first.url(:thumb_medium)
meta_tag_with_property('og:image', img_url)
end
end

def og_site_name
meta_tag_with_property('og:site_name', 'Diaspora*')
end

def og_description(post)
meta_tag_with_property('og:description', post_page_title(post))
end

def og_page_specific_tags(post)
[og_title(post), og_type(post),
og_url(post), og_image(post),
og_description(post)].join(' ').html_safe
end

def meta_tag_with_property(name, content)
content_tag(:meta, '', :property => name, :content => content)
end
end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%meta{:name => "description", :content => "Diaspora*"} %meta{:name => "description", :content => "Diaspora*"}
%meta{:name => "author", :content => "Diaspora, Inc."} %meta{:name => "author", :content => "Diaspora, Inc."}
= og_site_name
%link{:rel => 'shortcut icon', :href => "#{image_path('favicon.png')}" } %link{:rel => 'shortcut icon', :href => "#{image_path('favicon.png')}" }
%link{:rel => 'apple-touch-icon', :href => "#{image_path('apple-touch-icon.png')}"} %link{:rel => 'apple-touch-icon', :href => "#{image_path('apple-touch-icon.png')}"}
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.mobile.haml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%meta{:name => "MobileOptimized", :content => "320"} %meta{:name => "MobileOptimized", :content => "320"}
/ Force cleartype on WP7 / Force cleartype on WP7
%meta{'http-equiv' => "cleartype", :content => 'on'} %meta{'http-equiv' => "cleartype", :content => 'on'}
= og_site_name
/ Home screen icon (sized for retina displays) / Home screen icon (sized for retina displays)
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'} %link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
/ For Nokia devices / For Nokia devices
Expand All @@ -30,6 +30,7 @@
/%link{:rel => "apple-touch-startup-image", :href => "/images/apple-splash.png"} /%link{:rel => "apple-touch-startup-image", :href => "/images/apple-splash.png"}
/ Stylesheets / Stylesheets
= stylesheet_link_tag :mobile, :format => 'all' = stylesheet_link_tag :mobile, :format => 'all'
= yield(:custom_css) = yield(:custom_css)
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/post.html.haml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
%link{:rel => 'shortcut icon', :href => '/favicon.png'} %link{:rel => 'shortcut icon', :href => '/favicon.png'}
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'} %link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
= og_site_name
%title %title
= page_title yield(:page_title) = page_title yield(:page_title)
Expand Down Expand Up @@ -46,6 +47,7 @@
= current_user_atom_tag = current_user_atom_tag
- if @post.present? - if @post.present?
%link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"} %link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"}
= og_page_specific_tags(@post)


= yield(:head) = yield(:head)
= csrf_meta_tag = csrf_meta_tag
Expand Down

0 comments on commit 307ee15

Please sign in to comment.