From 0b092c9956544c50b6b09efb34884cc5b0e43cd7 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 7 Nov 2017 13:01:51 +0530 Subject: [PATCH] added og meta tags for page module. --- app/controllers/page_contents_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/page_contents_controller.rb b/app/controllers/page_contents_controller.rb index 06a9eb6..37e327c 100644 --- a/app/controllers/page_contents_controller.rb +++ b/app/controllers/page_contents_controller.rb @@ -12,6 +12,15 @@ class PageContentsController < OrbitAdminController html = page.page_contexts.last.content rescue "" url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : "" end + request = OrbitHelper.request + meta_desc = html.nil? ? "" : ActionView::Base.full_sanitizer.sanitize(html)[0..200] + doc = Nokogiri::HTML( html ) + img_srcs = doc.css('img').map{ |i| i['src'] } + metas = [{"property" => "og:title", "content" => name},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url},{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}] + if img_srcs.count > 0 + metas << {"property" => "og:image", "content" => "#{request.base_url}#{img_srcs[0]}"} + end + OrbitHelper.render_meta_tags(metas) { "html" => html,