-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
13,957 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"rules": [ | ||
"metascraper-amazon", | ||
"metascraper-author", | ||
"metascraper-date", | ||
"metascraper-description", | ||
"metascraper-image", | ||
"metascraper-logo", | ||
"metascraper-logo-favicon", | ||
"metascraper-publisher", | ||
"metascraper-title", | ||
"metascraper-url" | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/metascraper-logo-favicon/__snapshots__/index.js.snap-shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
exports['create an absolute faivcon url if the logo is not present 1'] = { | ||
"author": "Mat Follas", | ||
"title": "Vegetable Perfection: 100 delicious recipes for roots, bulbs, shoots and stems", | ||
"publisher": "Amazon", | ||
"image": "https://images-eu.ssl-images-amazon.com/images/I/61Q2c36lYeL._SX218_BO1,204,203,200_QL40_.jpg", | ||
"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.", | ||
"logo": "https://www.amazon.co.uk/favicon.ico", | ||
"url": "https://www.amazon.co.uk/Vegetable-Perfection-tasty-recipes-shoots/dp/1849757097/ref=asap_bc?ie=UTF8" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
'use strict' | ||
|
||
const { getUrl } = require('@metascraper/helpers') | ||
const { resolve: resolveUrl, URL } = require('url') | ||
|
||
const getFaviconUrl = url => { | ||
const {origin} = new URL(url) | ||
return resolveUrl(origin, 'favicon.ico') | ||
} | ||
|
||
module.exports = () => ({ | ||
logo: [({ htmlDom: $, meta, url }) => getUrl(url, `favicon.ico`)] | ||
logo: [({ htmlDom: $, meta, url }) => getFaviconUrl(url)] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13,881 changes: 13,881 additions & 0 deletions
13,881
packages/metascraper-logo-favicon/test/fixtures/input.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const clearModule = require('clear-module') | ||
const snapshot = require('snap-shot') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
const { omit } = require('lodash') | ||
const fs = require('fs') | ||
|
||
const readFile = promisify(fs.readFile) | ||
|
||
describe('metascraper amazon integration', () => { | ||
before(() => { | ||
clearModule.all() | ||
process.env.METASCRAPER_CONFIG_CWD = __dirname | ||
}) | ||
|
||
after(() => { | ||
clearModule.all() | ||
delete process.env.METASCRAPER_CONFIG_CWD | ||
}) | ||
|
||
describe('metascraper logo favicon', () => { | ||
it('create an absolute faivcon url if the logo is not present', async () => { | ||
const metascraper = require('metascraper') | ||
const html = await readFile(resolve(__dirname, 'fixtures/input.html')) | ||
const url = 'https://www.amazon.co.uk/Vegetable-Perfection-tasty-recipes-shoots/dp/1849757097/ref=asap_bc?ie=UTF8' | ||
const meta = omit(await metascraper({ html, url }), ['date']) | ||
snapshot(meta) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--require should | ||
--reporter spec | ||
--timeout 120000 | ||
--slow 300 | ||
--bail | ||
--recursive |