Skip to content

Commit

Permalink
fix: support relative canonical
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Sep 23, 2020
1 parent 0efaa0a commit 76b5cce
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -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]').
Expand Down

0 comments on commit 76b5cce

Please sign in to comment.