Ver código fonte

Allow search engines to crawl /offline &co

Thibaut Courouble 9 anos atrás
pai
commit
0cb57d5e98
2 arquivos alterados com 7 adições e 5 exclusões
  1. 6 0
      assets/javascripts/lib/page.coffee
  2. 1 5
      public/robots.txt

+ 6 - 0
assets/javascripts/lib/page.coffee

@@ -41,6 +41,7 @@ page.show = (path, state) ->
   currentState = context.state
   page.dispatch(context)
   context.pushState()
+  updateCanonicalLink()
   track()
   context
 
@@ -50,6 +51,7 @@ page.replace = (path, state, skipDispatch, init) ->
   currentState = context.state
   page.dispatch(context) unless skipDispatch
   context.replaceState()
+  updateCanonicalLink()
   track() unless init or skipDispatch
   context
 
@@ -177,6 +179,10 @@ onclick = (event) ->
 isSameOrigin = (url) ->
   url.indexOf("#{location.protocol}//#{location.hostname}") is 0
 
+updateCanonicalLink = ->
+  @canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
+  @canonicalLink.setAttribute('href', "http://#{location.host}#{location.pathname}")
+
 track = ->
   ga?('send', 'pageview', location.pathname + location.search + location.hash)
   _gauges?.push(['track'])

+ 1 - 5
public/robots.txt

@@ -1,6 +1,2 @@
 User-agent: *
-Disallow: /about
-Disallow: /news
-Disallow: /tips
-Disallow: /help
-Disallow: /offline
+Allow: /