1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

project preview in facebook open graph

This commit is contained in:
Sylvain 2016-07-28 17:44:58 +02:00
parent 5f96c9916d
commit dbc199cbba
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,11 @@
class SocialBotController < ActionController::Base
def share
case request.original_fullpath
when /=%2Fprojects%2F([\-0-9a-z]+)/
@project = Project.friendly.find("#{$1}")
else
puts "unknown bot request : #{request.original_url}"
end
end
end

View File

@ -59,4 +59,9 @@ class ProjectImageUploader < CarrierWave::Uploader::Base
def filename
"#{model.class.to_s.underscore}.#{file.extension}" if original_filename
end
# return an array like [width, height]
def dimensions
::MiniMagick::Image.open(file.file)[:dimensions]
end
end

View File

@ -0,0 +1,15 @@
<% image = @project.project_image.attachment.medium %>
<% width, height = image.dimensions %>
<!DOCTYPE html>
<html lang="<%= I18n.locale %>" ng-app="application" class="app">
<head>
<meta charset="utf-8">
<meta property="og:title" content="<%= @project.name %>"/>
<meta property="og:description" content="<%= strip_tags(@project.description) %>"/>
<meta property="og:image" content="<%= root_url+image.url %>"/>
<meta property="og:image:width" content="<%= width%>" />
<meta property="og:image:height" content="<%=height%>" />
<meta http-equiv="refresh" content="0;url=<%= root_url+'#!/projects/'+@project.slug %>">
</head>
</html>

View File

@ -17,6 +17,13 @@ Rails.application.routes.draw do
## The priority is based upon order of creation: first created -> highest priority.
## See how all your routes lay out with "rake routes".
constraints :user_agent => /facebookexternalhit\/[0-9]|Twitterbot|Pinterest|Google.*snippet/ do
root :to => 'social_bot#share', as: :bot_root
#TODO encode '#' in url with %23
# button => https://www.facebook.com/share.php?u=$URL
end
## You can have the root of your site routed with "root"
root 'application#index'