From 7af16471cd8a119a04ccd14249b34ce2d7a7eaf2 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 22 Mar 2017 15:37:27 -0600 Subject: [PATCH] if the asset_url is not present, attempt to find the canonical link tag. if not, warn the user and strip the query params. --- client/coral-embed/src/index.js | 11 ++++++++++- views/article.ejs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 21b159e8c..8ebd403b8 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -167,7 +167,16 @@ Talk.render = function (el, opts) { el.id = `_${Math.random()}`; } - let asset_url = opts.asset_url || window.location.href.split('#')[0]; + let asset_url = opts.asset_url; + if (!asset_url) { + try { + asset_url = document.querySelector('link[rel="canonical"]').href; + } catch (e) { + console.warn('This page does not include a canonical link tag. Talk has inferred this asset_url from the window object. Query params have been stripped, which may cause a single thread to be present across multiple pages.'); + asset_url = window.location.origin + window.location.pathname; + } + } + let comment = window.location.hash.slice(1); let query = { diff --git a/views/article.ejs b/views/article.ejs index 3869262ff..5f90cdf4d 100644 --- a/views/article.ejs +++ b/views/article.ejs @@ -27,7 +27,7 @@