From 76b5ccee20bd565b6de8f9ae9223d3bec151af33 Mon Sep 17 00:00:00 2001 From: Stanislav Popov Date: Wed, 23 Sep 2020 13:47:06 +0500 Subject: [PATCH] fix: support relative canonical --- src/scrap-site.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/scrap-site.js b/src/scrap-site.js index 7885d89..fa756c2 100644 --- a/src/scrap-site.js +++ b/src/scrap-site.js @@ -124,6 +124,10 @@ module.exports = async (baseUrl, options = {}) => { const domain2level = domainParts.slice(domainParts.length - 2). join('.'); const canonical = $('link[rel="canonical"]').attr('href'); + const relUrl = window.location.href.replace(`${window.location.protocol}//${window.location.host}`, ''); + const isCanonical = canonical ? + (canonical == decodeURI(window.location.href) || + canonical == decodeURI(relUrl) ? 1 : 0) : ''; const result = { request_time: window.performance.timing.responseEnd - @@ -165,8 +169,7 @@ module.exports = async (baseUrl, options = {}) => { '', keywords: $('meta[name="keywords"]').attr('content'), canonical: canonical, - is_canonical: canonical ? (canonical == - decodeURI(window.location.href) ? 1 : 0) : '', + is_canonical: isCanonical, og_title: $('meta[property="og:title"]').attr('content'), og_image: $('meta[property="og:image"]').attr('content'), schema_types: $.unique($('[itemtype]').