File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed
packages/metascraper-clearbit-logo Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const { URL } = require ( 'url' )
4
+ const got = require ( 'got' )
4
5
5
6
const DEFAULTS = {
6
7
size : '128' ,
@@ -13,9 +14,16 @@ module.exports = opts => {
13
14
opts = Object . assign ( { } , DEFAULTS , opts )
14
15
const { size, format } = opts
15
16
16
- const clearbitLogo = ( { htmlDom, meta, url : baseUrl } ) => {
17
- const { hostname } = new URL ( baseUrl )
18
- return `${ ENDPOINT } /${ hostname } ?size=${ size } &format=${ format } `
17
+ const clearbitLogo = async ( { url } ) => {
18
+ const { hostname } = new URL ( url )
19
+ const logoUrl = `${ ENDPOINT } /${ hostname } ?size=${ size } &format=${ format } `
20
+
21
+ try {
22
+ await got . head ( logoUrl )
23
+ return logoUrl
24
+ } catch ( err ) {
25
+ return null
26
+ }
19
27
}
20
28
21
29
return {
Original file line number Diff line number Diff line change 25
25
"mocha" : " latest" ,
26
26
"nyc" : " latest" ,
27
27
"should" : " latest" ,
28
- "snap-shot" : " latest" ,
29
28
"standard" : " latest"
30
29
},
31
30
"engines" : {
48
47
"env" : [
49
48
" mocha"
50
49
]
50
+ },
51
+ "dependencies" : {
52
+ "got" : " ~8.3.0"
51
53
}
52
54
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- const snapshot = require ( 'snap-shot ' )
3
+ const should = require ( 'should ' )
4
4
5
5
const metascraper = require ( 'metascraper' ) . load ( [
6
6
require ( 'metascraper-author' ) ( ) ,
@@ -15,10 +15,17 @@ const metascraper = require('metascraper').load([
15
15
] )
16
16
17
17
describe ( 'metascraper-clearbit-logo' , ( ) => {
18
- it ( 'if logo is not present, fallback to clearbit logo API ' , async ( ) => {
18
+ it ( 'returns when is possible resolve logo' , async ( ) => {
19
19
const url = 'https://facebook.com'
20
20
const html = '<div></div>'
21
21
const meta = await metascraper ( { html, url } )
22
- snapshot ( meta )
22
+ should ( meta . logo . indexOf ( 'clearbit' ) !== - 1 ) . be . true ( )
23
+ } )
24
+
25
+ it ( 'otherwise returns null' , async ( ) => {
26
+ const url = 'https://lolwerhere.com'
27
+ const html = '<div></div>'
28
+ const meta = await metascraper ( { html, url } )
29
+ should ( meta . logo ) . be . null ( )
23
30
} )
24
31
} )
You can’t perform that action at this time.
0 commit comments