History

Allow search engines to crawl /offline &co

Thibaut Courouble committed 10 years ago

Commit 0cb57d51 parent 6f75f3c2 files · +7 −5Browse files

Showing the changes to assets/javascripts (1 of 2 files). Show all

Unified · Split

assets/javascripts/lib/page.coffee+6−0
@@ -41,6 +41,7 @@ page.show = (path, state) -> · 40 unmodified lines
4141 currentState = context.state
4242 page.dispatch(context)
4343 context.pushState()
44+ updateCanonicalLink()
4445 track()
4546 context
4647
@@ -50,6 +51,7 @@ page.replace = (path, state, skipDispatch, init) -> · 3 unmodified lines
5051 currentState = context.state
5152 page.dispatch(context) unless skipDispatch
5253 context.replaceState()
54+ updateCanonicalLink()
5355 track() unless init or skipDispatch
5456 context
5557
@@ -177,6 +179,10 @@ onclick = (event) -> · 121 unmodified lines
177179 isSameOrigin = (url) ->
178180 url.indexOf("#{location.protocol}//#{location.hostname}") is 0
179181
182+updateCanonicalLink = ->
183+ @canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
184+ @canonicalLink.setAttribute('href', "http://#{location.host}#{location.pathname}")
185+
180186 track = ->
181187 ga?('send', 'pageview', location.pathname + location.search + location.hash)
182188 _gauges?.push(['track'])