From 88098f390b46b0622fc399dda04c8aad59a375a7 Mon Sep 17 00:00:00 2001 From: Miah Raihan Mahmud Arman Date: Wed, 17 Dec 2014 13:54:50 +0100 Subject: [PATCH] Added wiselinks_keywords for SEO --- lib/assets/javascripts/_request_manager.js.coffee | 6 ++++++ lib/assets/javascripts/_response.js.coffee | 9 +++++++++ lib/wiselinks/controller_methods.rb | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/assets/javascripts/_request_manager.js.coffee b/lib/assets/javascripts/_request_manager.js.coffee index f735c0c..f32ee25 100644 --- a/lib/assets/javascripts/_request_manager.js.coffee +++ b/lib/assets/javascripts/_request_manager.js.coffee @@ -81,6 +81,7 @@ class RequestManager => @_title(response.title()) @_description(response.description()) + @_keywords(response.keywords()) @_canonical(response.canonical()) @_robots(response.robots()) @_link_rel_prev(response.link_rel_prev()) @@ -106,6 +107,11 @@ class RequestManager $(document).trigger('page:description', decodeURI(value)) $('meta[name="description"]').attr('content', decodeURI(value)) + _keywords: (value) -> + if value? + $(document).trigger('page:keywords', decodeURI(value)) + $('meta[name="keywords"]').attr('content', decodeURI(value)) + _canonical: (value) -> if value? $(document).trigger('page:canonical', decodeURI(value)) diff --git a/lib/assets/javascripts/_response.js.coffee b/lib/assets/javascripts/_response.js.coffee index 548354d..e6057dd 100644 --- a/lib/assets/javascripts/_response.js.coffee +++ b/lib/assets/javascripts/_response.js.coffee @@ -42,6 +42,15 @@ class Response else @xhr.getResponseHeader('X-Wiselinks-Description') + keywords: -> + @_keywords ?= @_extract_keywords() + + _extract_keywords: -> + if @_is_full_document_response() + $('meta[name="keywords"]', @_get_doc()).text() + else + @xhr.getResponseHeader('X-Wiselinks-Keywords') + canonical: -> @_canonical ?= @_extract_canonical() diff --git a/lib/wiselinks/controller_methods.rb b/lib/wiselinks/controller_methods.rb index 20375b8..59e3dc1 100644 --- a/lib/wiselinks/controller_methods.rb +++ b/lib/wiselinks/controller_methods.rb @@ -4,6 +4,7 @@ module ControllerMethods def self.included(base) base.helper_method :wiselinks_title base.helper_method :wiselinks_description + base.helper_method :wiselinks_keywords base.helper_method :wiselinks_canonical base.helper_method :wiselinks_robots base.helper_method :wiselinks_link_rel_prev @@ -31,6 +32,13 @@ def wiselinks_description(value) end end + def wiselinks_keywords(value) + if self.request.wiselinks? && value.present? + Wiselinks.log("keywords: #{value}") + self.response.headers['X-Wiselinks-Keywords'] = URI.encode(value) + end + end + def wiselinks_canonical(value) if self.request.wiselinks? && value.present? Wiselinks.log("canonical: #{value}")