Permalink
Browse files

hella open graph tags

added some basic open graph tags to the posts#show page.
  • Loading branch information...
1 parent d0b7833 commit 307ee15884fdd07c87044b0939e5d738d6e41d12 @maxwell maxwell committed Apr 20, 2012
View
38 app/helpers/open_graph_helper.rb
@@ -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
View
1 app/views/layouts/application.html.haml
@@ -11,6 +11,7 @@
%meta{:name => "description", :content => "Diaspora*"}
%meta{:name => "author", :content => "Diaspora, Inc."}
+ = og_site_name
%link{:rel => 'shortcut icon', :href => "#{image_path('favicon.png')}" }
%link{:rel => 'apple-touch-icon', :href => "#{image_path('apple-touch-icon.png')}"}
View
3 app/views/layouts/application.mobile.haml
@@ -18,7 +18,7 @@
%meta{:name => "MobileOptimized", :content => "320"}
/ Force cleartype on WP7
%meta{'http-equiv' => "cleartype", :content => 'on'}
-
+ = og_site_name
/ Home screen icon (sized for retina displays)
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
/ For Nokia devices
@@ -30,6 +30,7 @@
/%link{:rel => "apple-touch-startup-image", :href => "/images/apple-splash.png"}
/ Stylesheets
+
= stylesheet_link_tag :mobile, :format => 'all'
= yield(:custom_css)
View
2 app/views/layouts/post.html.haml
@@ -19,6 +19,7 @@
%link{:rel => 'shortcut icon', :href => '/favicon.png'}
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
+ = og_site_name
%title
= page_title yield(:page_title)
@@ -46,6 +47,7 @@
= current_user_atom_tag
- if @post.present?
%link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"}
+ = og_page_specific_tags(@post)
= yield(:head)
= csrf_meta_tag

0 comments on commit 307ee15

Please sign in to comment.