11'use strict'
22
3- const { isEmpty, first, toNumber, chain , orderBy } = require ( 'lodash' )
3+ const { isEmpty, first, toNumber, orderBy } = require ( 'lodash' )
44const reachableUrl = require ( 'reachable-url' )
55const memoize = require ( '@keyvhq/memoize' )
66
@@ -27,10 +27,7 @@ const isValidContenType = (contentType, contentTypes) =>
2727const toSize = ( input , url ) => {
2828 if ( isEmpty ( input ) ) return
2929
30- const [ verticalSize , horizontalSize ] = chain ( input )
31- . replace ( / × / g, 'x' )
32- . split ( 'x' )
33- . value ( )
30+ const [ verticalSize , horizontalSize ] = input . replace ( / × / g, 'x' ) . split ( 'x' )
3431
3532 const height = toNumber ( verticalSize ) || 0
3633 const width = toNumber ( horizontalSize ) || 0
@@ -67,30 +64,31 @@ const getSize = (url, sizes) =>
6764 toSize . fallback ( url )
6865
6966const getDomNodeSizes = ( domNodes , attr , url ) =>
70- chain ( domNodes )
71- . reduce ( ( acc , domNode ) => {
72- const relativeUrl = domNode . attribs [ attr ]
73- if ( ! relativeUrl || relativeUrl === url ) return acc
74- const normalizedUrl = normalizeUrl ( url , relativeUrl )
75- if ( ! normalizedUrl ) return acc
76- return [
77- ...acc ,
78- {
79- ...domNode . attribs ,
80- url : normalizedUrl ,
81- size : getSize ( normalizedUrl , domNode . attribs . sizes )
82- }
83- ]
84- } , [ ] )
85- . value ( )
67+ domNodes . reduce ( ( acc , domNode ) => {
68+ const relativeUrl = domNode . attribs [ attr ]
69+ if ( ! relativeUrl || relativeUrl === url ) return acc
70+
71+ const normalizedUrl = normalizeUrl ( url , relativeUrl )
72+ if ( ! normalizedUrl ) return acc
73+
74+ acc . push ( {
75+ ...domNode . attribs ,
76+ url : normalizedUrl ,
77+ size : getSize ( normalizedUrl , domNode . attribs . sizes )
78+ } )
79+
80+ return acc
81+ } , [ ] )
8682
8783const getSizes = ( $ , collection , url ) =>
88- chain ( collection )
89- . reduce ( ( acc , { tag, attr } ) => {
90- const domNodes = $ ( tag ) . get ( )
91- return [ ...acc , ...getDomNodeSizes ( domNodes , attr , url ) ]
92- } , [ ] )
93- . value ( )
84+ collection . reduce ( ( acc , { tag, attr } ) => {
85+ const domNodes = $ ( tag ) . get ( )
86+ const domNodeSizes = getDomNodeSizes ( domNodes , attr , url )
87+
88+ for ( const size of domNodeSizes ) acc . push ( size )
89+
90+ return acc
91+ } , [ ] )
9492
9593const sizeSelectors = [
9694 { tag : 'link[rel*="icon" i]' , attr : 'href' } , // apple-icon, // fluid-icon
@@ -187,13 +185,17 @@ const createGetLogo = ({
187185 withFavicon,
188186 withGoogle
189187} ) => {
190- const getLogo = async url => {
191- const providers = ALLOWED_EXTENSION_CONTENT_TYPES . map (
192- ext => withFavicon && createFavicon ( ext , resolveFaviconUrl )
193- )
194- . concat ( withGoogle && google )
195- . filter ( Boolean )
188+ const providers = [ ]
189+
190+ if ( withFavicon ) {
191+ for ( const extensionAndTypes of ALLOWED_EXTENSION_CONTENT_TYPES ) {
192+ providers . push ( createFavicon ( extensionAndTypes , resolveFaviconUrl ) )
193+ }
194+ }
195+
196+ if ( withGoogle ) providers . push ( google )
196197
198+ const getLogo = async url => {
197199 for ( const provider of providers ) {
198200 const logoUrl = await provider ( url , { gotOpts } )
199201 if ( logoUrl ) return logoUrl
0 commit comments