diff --git a/app/helpers/open_graph_helper.rb b/app/helpers/open_graph_helper.rb new file mode 100644 index 000000000..aa20e1210 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 22984d4aa..3e2225d99 100644 --- a/app/views/layouts/application.html.haml +++ b/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')}"} diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 11b15173d..071db2045 100644 --- a/app/views/layouts/application.mobile.haml +++ b/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) diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index 98f941219..ae393cd62 100644 --- a/app/views/layouts/post.html.haml +++ b/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