From 0cb57d5e980bfb7e71f2c727974a3fa7cd36d267 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 16 Oct 2016 10:12:45 -0400 Subject: [PATCH] Allow search engines to crawl /offline &co --- assets/javascripts/lib/page.coffee | 6 ++++++ public/robots.txt | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/assets/javascripts/lib/page.coffee b/assets/javascripts/lib/page.coffee index 546f5f8d..246cff25 100644 --- a/assets/javascripts/lib/page.coffee +++ b/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']) diff --git a/public/robots.txt b/public/robots.txt index 5447d6f0..14267e90 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,6 +1,2 @@ User-agent: * -Disallow: /about -Disallow: /news -Disallow: /tips -Disallow: /help -Disallow: /offline +Allow: / \ No newline at end of file