fetch-opengraph
Advanced tools
Comparing version 1.0.17 to 1.0.19
43
index.js
@@ -33,7 +33,17 @@ "use strict"; | ||
try { | ||
const response = yield axios_1.default.get(url); | ||
const response = yield axios_1.default.get(url, { | ||
headers: { | ||
'Cache-Control': 'no-cache', | ||
'User-Agent': 'PostmanRuntime/7.26.10', | ||
Accept: '*/*', | ||
Connection: 'keep-alive' | ||
} | ||
}); | ||
if (response.status >= 400) { | ||
throw response; | ||
} | ||
let siteTitle = ''; | ||
const html = yield response.data; | ||
const tagTitle = html.match(/<title[^>]*>[\r\n\t\s]*([^<]+)[\r\n\t\s]*<\/title>/gim); | ||
siteTitle = tagTitle[0].replace(/<title[^>]*>[\r\n\t\s]*([^<]+)[\r\n\t\s]*<\/title>/gim, '$1'); | ||
const metas = html.match(/<meta[^>]+>/gim); | ||
@@ -79,2 +89,7 @@ const og = []; | ||
const result = og.reduce((chain, meta) => (Object.assign(Object.assign({}, chain), { [meta.name]: meta.value })), {}); | ||
// Image | ||
result[ogImage] = result[ogImage] ? result[ogImage] : null; | ||
result[twitterImage] = result[twitterImage] | ||
? result[twitterImage] | ||
: result[ogImage]; | ||
result.image = result[ogImage] | ||
@@ -85,7 +100,23 @@ ? result[ogImage] | ||
: null; | ||
result.url = result[ogUrl] | ||
? result[ogUrl] | ||
: result[twitterUrl] | ||
? result[twitterUrl] | ||
: url; | ||
// URL | ||
result[ogUrl] = result[ogUrl] ? result[ogUrl] : url; | ||
result[twitterUrl] = result[twitterUrl] | ||
? result[twitterUrl] | ||
: result[ogUrl]; | ||
result.url = result[ogUrl]; | ||
// Description | ||
result[ogDescription] = result[ogDescription] | ||
? result[ogDescription] | ||
: result.description; | ||
result[twitterDescription] = result[twitterDescription] | ||
? result[twitterDescription] | ||
: result[ogDescription]; | ||
// Title | ||
result[ogTitle] = result[ogTitle] ? result[ogTitle] : siteTitle; | ||
result[twitterTitle] = result[twitterTitle] | ||
? result[twitterTitle] | ||
: result[ogTitle]; | ||
result.title = result[ogTitle]; | ||
// Type | ||
result[ogType] = result[ogType] ? result[ogType] : 'website'; | ||
return resolve(result); | ||
@@ -92,0 +123,0 @@ } |
{ | ||
"name": "fetch-opengraph", | ||
"version": "1.0.17", | ||
"version": "1.0.19", | ||
"description": "Fetch opengraph information from an url", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
11387
149