Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Added wiselinks_keywords for SEO #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/assets/javascripts/_request_manager.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions lib/assets/javascripts/_response.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 8 additions & 0 deletions lib/wiselinks/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down