Commit 93747a6e by Truong Ba Dieu

Add meta for share

parent 8cb0cc71
class ProductsController < ApplicationController class ProductsController < ApplicationController
include ApplicationHelper
before_action :get_categories before_action :get_categories
before_action :authenticate_user!, :only => [:new, :create] before_action :authenticate_user!, :only => [:new, :create]
after_action :verify_authorized, :only => [:new, :create] after_action :verify_authorized, :only => [:new, :create]
...@@ -9,6 +11,9 @@ class ProductsController < ApplicationController ...@@ -9,6 +11,9 @@ class ProductsController < ApplicationController
@product = Product.find(params[:id]) @product = Product.find(params[:id])
add_breadcrumb @product.category.try(:name), category_path(@product.category.try(:id)) add_breadcrumb @product.category.try(:name), category_path(@product.category.try(:id))
add_breadcrumb @product.title add_breadcrumb @product.title
fetch_social_info(@product.title, @product.title, @product.image.thumb("158x158#").url)
render layout: "share_social"
end end
def new def new
......
module ApplicationHelper module ApplicationHelper
include ActionView::Helpers::TextHelper
def currency_number(price=0, currency="usd") def currency_number(price=0, currency="usd")
"#{currency}#{price}" "#{currency}#{price}"
end end
...@@ -7,4 +9,13 @@ module ApplicationHelper ...@@ -7,4 +9,13 @@ module ApplicationHelper
Category.pluck(:name, :id) Category.pluck(:name, :id)
end end
def current_url
request.original_url
end
def fetch_social_info(title, description, image)
@title = "Venshop | #{truncate(title, length: 60)}"
@description = truncate(description, length: 150)
@image = "#{request.base_url}#{image}"
end
end end
...@@ -4,10 +4,10 @@ require 'rsolr' ...@@ -4,10 +4,10 @@ require 'rsolr'
class SolrService class SolrService
def self.search(params={}) def self.search(params={})
params[:page] ||= 1 params[:page] ||= 1
params[:keyword] ||= "" keyword = params[:keyword] || ""
params[:keyword] = params[:keyword].gsub("^", "").gsub(":", "").gsub("(", "").gsub(")", "") keyword = keyword.gsub("^", "").gsub(":", "").gsub("(", "").gsub(")", "")
solr = RSolr.connect :url => ENV["solr_url"] solr = RSolr.connect :url => ENV["solr_url"]
res = solr.paginate params[:page], ENV["default_perpage"], 'select', :params => {:q => "*#{params[:keyword]}*"} res = solr.paginate params[:page], ENV["default_perpage"], 'select', :params => {:q => "*#{keyword}*"}
res["response"]["docs"] res["response"]["docs"]
end end
......
...@@ -11,17 +11,25 @@ ...@@ -11,17 +11,25 @@
<!-- Schema.org markup for Google+ --> <!-- Schema.org markup for Google+ -->
<meta itemprop="name" content="<%= @title %>"> <meta itemprop="name" content="<%= @title %>">
<meta itemprop="description" content="<%= @description %>""> <meta itemprop="description" content="<%= @description %>">
<meta itemprop="image" content="<%= @image %>""> <meta itemprop="image" content="<%= @image %>">
<!-- Twitter Card data -->
<meta name="twitter:card" content="product">
<meta name="twitter:site" content="@venshop">
<meta name="twitter:title" content="<%= @title %>">
<meta name="twitter:description" content="<%= @description %>">
<meta name="twitter:creator" content="@venshop">
<meta name="twitter:image" content="<%= @image %>">
<!-- Open Graph data --> <!-- Open Graph data -->
<meta property="og:title" content="Title Here" /> <meta property="og:title" content="<%= @title %>" />
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
<meta property="og:url" content="http://www.example.com/" /> <meta property="og:url" content="<%= current_url %>" />
<meta property="og:image" content="http://example.com/image.jpg" /> <meta property="og:image" content="<%= @image %>" />
<meta property="og:description" content="Description Here" /> <meta property="og:description" content="<%= @description %>" />
<meta property="og:site_name" content="Site Name, i.e. Moz" /> <meta property="og:site_name" content="<%= @title %>" />
<meta property="article:published_time" content="2013-09-17T05:59:00+01:00" /> <meta property="article:published_time" content="2013-09-17T05:59:00+01:00" />
<meta property="article:modified_time" content="2013-09-16T19:08:47+01:00" /> <meta property="article:modified_time" content="2013-09-16T19:08:47+01:00" />
<meta property="article:section" content="Article Section" /> <meta property="article:section" content="Article Section" />
......
...@@ -7,4 +7,9 @@ ...@@ -7,4 +7,9 @@
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
User.create(name: "admin", email: "admin@gmail.com", password: "abc123456") if User.find_by(email: "admin@gmail.com").blank? u = User.find_by(email: "admin@gmail.com")
\ No newline at end of file if u.blank?
u = User.create(name: "admin", email: "admin@gmail.com", password: "abc123456")
end
u.role = User.roles[:admin]
u.save
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment