Skip to content

Commit 266b404

Browse files
committed
Ensure favicon path is absolute
1 parent 2aab9e7 commit 266b404

File tree

7 files changed

+13957
-6
lines changed

7 files changed

+13957
-6
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"rules": [
3+
"metascraper-amazon",
4+
"metascraper-author",
5+
"metascraper-date",
6+
"metascraper-description",
7+
"metascraper-image",
8+
"metascraper-logo",
9+
"metascraper-logo-favicon",
10+
"metascraper-publisher",
11+
"metascraper-title",
12+
"metascraper-url"
13+
]
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports['create an absolute faivcon url if the logo is not present 1'] = {
2+
"author": "Mat Follas",
3+
"title": "Vegetable Perfection: 100 delicious recipes for roots, bulbs, shoots and stems",
4+
"publisher": "Amazon",
5+
"image": "https://images-eu.ssl-images-amazon.com/images/I/61Q2c36lYeL._SX218_BO1,204,203,200_QL40_.jpg",
6+
"description": "Buy Vegetable Perfection: 100 delicious recipes for roots, bulbs, shoots and stems by Mat Follas (ISBN: 9781849757096) from Amazon’s Book Store. Everyday low prices and free delivery on eligible orders.",
7+
"logo": "https://www.amazon.co.uk/favicon.ico",
8+
"url": "https://www.amazon.co.uk/Vegetable-Perfection-tasty-recipes-shoots/dp/1849757097/ref=asap_bc?ie=UTF8"
9+
}
10+
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict'
22

3-
const { getUrl } = require('@metascraper/helpers')
3+
const { resolve: resolveUrl, URL } = require('url')
4+
5+
const getFaviconUrl = url => {
6+
const {origin} = new URL(url)
7+
return resolveUrl(origin, 'favicon.ico')
8+
}
49

510
module.exports = () => ({
6-
logo: [({ htmlDom: $, meta, url }) => getUrl(url, `favicon.ico`)]
11+
logo: [({ htmlDom: $, meta, url }) => getFaviconUrl(url)]
712
})

packages/metascraper-logo-favicon/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
"clearbit",
2121
"metascraper"
2222
],
23-
"dependencies": {
24-
"@metascraper/helpers": "^3.3.0"
25-
},
2623
"devDependencies": {
24+
"clear-module": "latest",
25+
"lodash": "latest",
26+
"mocha": "latest",
27+
"nyc": "latest",
28+
"should": "latest",
29+
"snap-shot": "latest",
2730
"standard": "latest"
2831
},
2932
"engines": {
@@ -33,7 +36,7 @@
3336
"index.js"
3437
],
3538
"scripts": {
36-
"test": "exit 0"
39+
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc mocha test"
3740
},
3841
"license": "MIT",
3942
"lint-staged": {

packages/metascraper-logo-favicon/test/fixtures/input.html

Lines changed: 13881 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
const clearModule = require('clear-module')
4+
const snapshot = require('snap-shot')
5+
const { promisify } = require('util')
6+
const { resolve } = require('path')
7+
const { omit } = require('lodash')
8+
const fs = require('fs')
9+
10+
const readFile = promisify(fs.readFile)
11+
12+
describe('metascraper amazon integration', () => {
13+
before(() => {
14+
clearModule.all()
15+
process.env.METASCRAPER_CONFIG_CWD = __dirname
16+
})
17+
18+
after(() => {
19+
clearModule.all()
20+
delete process.env.METASCRAPER_CONFIG_CWD
21+
})
22+
23+
describe('metascraper logo favicon', () => {
24+
it('create an absolute faivcon url if the logo is not present', async () => {
25+
const metascraper = require('metascraper')
26+
const html = await readFile(resolve(__dirname, 'fixtures/input.html'))
27+
const url = 'https://www.amazon.co.uk/Vegetable-Perfection-tasty-recipes-shoots/dp/1849757097/ref=asap_bc?ie=UTF8'
28+
const meta = omit(await metascraper({ html, url }), ['date'])
29+
snapshot(meta)
30+
})
31+
})
32+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--require should
2+
--reporter spec
3+
--timeout 120000
4+
--slow 300
5+
--bail
6+
--recursive

0 commit comments

Comments
 (0)