Parse canonical url of cross device supported web sites.
Many web applications redirect to a different url when browsing them from desktop or mobile devices.
This module makes it easy to parse the canonical and alternate url that almost every supported web application provides.
This module simply grabs the canonical/alternate href attribute from the html response of the given url.
Examples:
<link rel="canonical" href="https://www.linkedin.com/?trk=">
<link rel="alternate" hreflang="en-il" href="https://il.linkedin.com/">
npm install parse-canonical-url
This module return a promise and this is how to use it:
var parseCanonicalUrl = require('parse-canonical-url');
return parseCanonicalUrl.canonical(askedUrl)
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.log(err);
});
OR
var parseCanonicalUrl = require('parse-canonical-url');
return parseCanonicalUrl.alternate(askedUrl)
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.log(err);
});
Copyright (c) 2015 Adam Gavish
Licensed under the MIT license.