link-preview-js
Advanced tools
Comparing version 1.4.4 to 1.5.0
@@ -71,2 +71,10 @@ const LinkPreview = require('../index.js'); | ||
it('should make request with different languages', async () => { | ||
let linkInfo = await LinkPreview.getPreview('https://www.hsbc.ca/', {language: 'fr'}); | ||
expect(linkInfo.title).to.be.equal('Particuliers | HSBC Canada'); | ||
linkInfo = await LinkPreview.getPreview('https://www.hsbc.ca/'); | ||
expect(linkInfo.title).to.be.equal('HSBC Personal Banking | HSBC Canada'); | ||
}); | ||
it('should handle audio urls', async () => { | ||
@@ -73,0 +81,0 @@ const linkInfo = await LinkPreview.getPreview('https://ondemand.npr.org/anon.npr-mp3/npr/atc/2007/12/20071231_atc_13.mp3'); |
10
index.js
@@ -25,3 +25,9 @@ const cheerio = require('cheerio-without-node-native'); | ||
if (detectedUrl) { | ||
fetch(detectedUrl) | ||
var fetchOptions = {} | ||
if (options && options.language) { | ||
fetchOptions.headers = { | ||
'Accept-Language': options.language | ||
} | ||
} | ||
fetch(detectedUrl, fetchOptions) | ||
.then(function (response) { | ||
@@ -246,3 +252,3 @@ | ||
width: width, | ||
height: width | ||
height: height | ||
}; | ||
@@ -249,0 +255,0 @@ if (videoType && videoType.indexOf('video/') === 0) { |
{ | ||
"name": "link-preview-js", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,2 +40,3 @@ | ||
| imagesPropertyType (**optional**) (ex: 'og') | Fetches images only with the specified property, `meta[property='${imagesPropertyType}:image']` | | ||
| language (**optional**) (ex: 'de', 'en-US') | Fetch content with specific language | | ||
@@ -48,2 +49,3 @@ | ||
imagesPropertyType: 'og', // fetches only open-graph images | ||
language: 'fr-CA', // fetches site for French language | ||
}) | ||
@@ -50,0 +52,0 @@ .then(data => console.debug(data)); |
25873
454
124