react-native-link-preview
Advanced tools
Comparing version 1.3.0 to 1.3.1
36
index.js
@@ -51,3 +51,4 @@ /** | ||
images: getImages(doc, url, options.imagesPropertyType), | ||
videos: getVideos(doc) | ||
videos: getVideos(doc), | ||
favicons: getFavicons(doc, url) | ||
}; | ||
@@ -186,2 +187,35 @@ }; | ||
// returns an array of URL's to favicon images | ||
const getFavicons = function(doc, rootUrl) { | ||
let images = [], | ||
nodes = [], | ||
src; | ||
const relSelectors = ['rel=icon', 'rel="shortcut icon"', 'rel=apple-touch-icon']; | ||
relSelectors.forEach((relSelector) => { | ||
// look for all icon tags | ||
nodes = doc(`link[${relSelector}]`); | ||
// collect all images from icon tags | ||
if (nodes.length) { | ||
nodes.each((index, node) => { | ||
src = node.attribs.href; | ||
if (src) { | ||
src = urlObj.resolve(rootUrl, src); | ||
images.push(src); | ||
} | ||
}); | ||
} | ||
}); | ||
// if no icon images, use default favicon location | ||
if (images.length <= 0) { | ||
src = '/favicon.ico'; | ||
images.push(urlObj.resolve(rootUrl, src)); | ||
} | ||
return images; | ||
}; | ||
// const parseMediaResponse = function(res, contentType, url) { | ||
@@ -188,0 +222,0 @@ // if (contentType.indexOf('image/') === 0) { |
{ | ||
"name": "react-native-link-preview", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,4 +32,4 @@ | ||
| Property Name | Result | | ||
| ------------- |:-------------:| | ||
| Property Name | Result | | ||
| ------------- |:-------------:| | ||
| imagesPropertyType (**optional**) (ex: 'og') | Fetches images only with the specified property, `meta[property='${imagesPropertyType}:image']` | | ||
@@ -40,3 +40,3 @@ | ||
LinkPreview.getPreview( | ||
'https://www.youtube.com/watch?v=MejbOFk7H6c', | ||
'https://www.youtube.com/watch?v=MejbOFk7H6c', | ||
{ | ||
@@ -57,3 +57,4 @@ imagesPropertyType: 'og', // fetches only open-graph images | ||
mediaType: "video", | ||
videos: [] | ||
videos: [], | ||
favicons:["https://www.youtube.com/yts/img/favicon_32-vflOogEID.png","https://www.youtube.com/yts/img/favicon_48-vflVjB_Qk.png","https://www.youtube.com/yts/img/favicon_96-vflW9Ec0w.png","https://www.youtube.com/yts/img/favicon_144-vfliLAfaB.png","https://s.ytimg.com/yts/img/favicon-vfl8qSV2F.ico"] | ||
} | ||
@@ -60,0 +61,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144736
274
63