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

Commit

Permalink
Merge pull request #68 from cfiorini/meta_url
Browse files Browse the repository at this point in the history
Added more stuff for SEO techniques
  • Loading branch information
igor-alexandrov committed Apr 2, 2014
2 parents b837377 + 9ebb417 commit fa9e7b8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/assets/javascripts/_request_manager.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RequestManager
self._html_loaded($target, data, status, xhr)
).fail(
(xhr, status, error) ->
self._fail($target, status, state, error, xhr.status)
self._fail($target, status, state, error, xhr.status, xhr.responseText)
).always(
(data_or_xhr, status, xhr_or_error)->
self._always($target, status, state)
Expand Down Expand Up @@ -81,12 +81,16 @@ class RequestManager
=>
@_title(response.title())
@_description(response.description())
@_canonical(response.canonical())
@_robots(response.robots())
@_link_rel_prev(response.link_rel_prev())
@_link_rel_next(response.link_rel_next())
@_done($target, status, state, response.content())
)

_fail: ($target, status, state, error, code) ->
_fail: ($target, status, state, error, code, data) ->
$(document).trigger('page:fail'
[$target, status, decodeURI(state.url), error, code]
[$target, status, decodeURI(state.url), error, code, data]
)

_always: ($target, status, state) ->
Expand All @@ -102,6 +106,26 @@ class RequestManager
$(document).trigger('page:description', decodeURI(value))
$('meta[name="description"]').attr('content', decodeURI(value))

_canonical: (value) ->
if value?
$(document).trigger('page:canonical', decodeURI(value))
$('link[rel="canonical"]').attr('href', decodeURI(value))

_robots: (value) ->
if value?
$(document).trigger('page:robots', decodeURI(value))
$('meta[name="robots"]').attr('content', decodeURI(value))

_link_rel_prev: (value) ->
if value?
$(document).trigger('page:link_rel_prev', decodeURI(value))
$('link[rel="prev"]').attr('href', decodeURI(value))

_link_rel_next: (value) ->
if value?
$(document).trigger('page:link_rel_next', decodeURI(value))
$('link[rel="next"]').attr('href', decodeURI(value))


window._Wiselinks = {} if window._Wiselinks == undefined
window._Wiselinks.RequestManager = RequestManager
38 changes: 38 additions & 0 deletions lib/assets/javascripts/_response.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,44 @@ class Response
else
@xhr.getResponseHeader('X-Wiselinks-Description')

canonical: ->
@_canonical ?= @_extract_canonical()

_extract_canonical: ->
if @_is_full_document_response()
$('link[rel="canonical"]', @_get_doc()).text()
else
@xhr.getResponseHeader('X-Wiselinks-Canonical')


robots: ->
@_robots ?= @_extract_robots()

_extract_robots: ->
if @_is_full_document_response()
$('meta[name="robots"]', @_get_doc()).text()
else
@xhr.getResponseHeader('X-Wiselinks-Robots')


link_rel_prev: ->
@_link_rel_prev ?= @_extract_link_rel_prev()

_extract_link_rel_prev: ->
if @_is_full_document_response()
$('link[rel="prev"]', @_get_doc()).text()
else
@xhr.getResponseHeader('X-Wiselinks-LinkRelPrev')

link_rel_next: ->
@_link_rel_next ?= @_extract_link_rel_next()

_extract_link_rel_next: ->
if @_is_full_document_response()
$('link[rel="next"]', @_get_doc()).text()
else
@xhr.getResponseHeader('X-Wiselinks-LinkRelNext')

_extract_content: ->
if @_is_full_document_response()
@_get_doc_target_node().html()
Expand Down
32 changes: 32 additions & 0 deletions lib/wiselinks/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module ControllerMethods
def self.included(base)
base.helper_method :wiselinks_title
base.helper_method :wiselinks_description
base.helper_method :wiselinks_canonical
base.helper_method :wiselinks_robots
base.helper_method :wiselinks_link_rel_prev
base.helper_method :wiselinks_link_rel_next
base.before_filter :set_wiselinks_url
end

Expand All @@ -27,6 +31,34 @@ def wiselinks_description(value)
end
end

def wiselinks_canonical(value)
if self.request.wiselinks? && value.present?
Wiselinks.log("canonical: #{value}")
self.response.headers['X-Wiselinks-Canonical'] = URI.encode(value)
end
end

def wiselinks_robots(value)
if self.request.wiselinks? && value.present?
Wiselinks.log("robots: #{value}")
self.response.headers['X-Wiselinks-Robots'] = URI.encode(value)
end
end

def wiselinks_link_rel_prev(value)
if self.request.wiselinks? && value.present?
Wiselinks.log("link_rel_prev: #{value}")
self.response.headers['X-Wiselinks-LinkRelPrev'] = URI.encode(value)
end
end

def wiselinks_link_rel_next(value)
if self.request.wiselinks? && value.present?
Wiselinks.log("link_rel_next: #{value}")
self.response.headers['X-Wiselinks-LinkRelNext'] = URI.encode(value)
end
end

def set_wiselinks_url
# self.response.headers['X-Wiselinks-Url'] = request.env['REQUEST_URI'] if self.request.wiselinks?
self.response.headers['X-Wiselinks-Url'] = request.url if self.request.wiselinks?
Expand Down

0 comments on commit fa9e7b8

Please sign in to comment.