Skip to content

Commit cfe41bb

Browse files
committed
fix(metascraper-logo-favicon): allow URL input and apply priority. closes #724
1 parent 7a504f7 commit cfe41bb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/metascraper-logo-favicon/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const getDomNodeSizes = (domNodes, attr, url) =>
7878
{
7979
...domNode.attribs,
8080
url: normalizedUrl,
81-
size: getSize(url, domNode.attribs.sizes)
81+
size: getSize(normalizedUrl, domNode.attribs.sizes)
8282
}
8383
]
8484
}, [])
@@ -163,8 +163,8 @@ const createFavicon = (
163163
const faviconUrl = logo(`/favicon.${ext}`, { url })
164164
return faviconUrl
165165
? resolveFaviconUrl(faviconUrl, contentTypes, gotOpts).then(
166-
response => response?.url
167-
)
166+
response => response?.url
167+
)
168168
: undefined
169169
}
170170
}

packages/metascraper-logo-favicon/test/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ test('get the biggest icon possible', async t => {
8585
t.is(metadata.logo, 'https://cdn.microlink.io/logo/favicon-196x196.png')
8686
})
8787

88+
test('prefers small png over large ico', async t => {
89+
const url = 'https://github.com'
90+
const metascraper = createMetascraper()
91+
const html = createHtml([
92+
'<link rel="icon" type="image/png" href="/fluidicon.png" sizes="96x96">',
93+
'<link rel="icon" type="image/x-icon" href="/favicon.ico" sizes="128x128">'
94+
])
95+
const metadata = await metascraper({ url, html })
96+
t.is(metadata.logo, 'https://github.com/fluidicon.png')
97+
})
98+
8899
test('detect `rel="fluid-icon"`', async t => {
89100
const url = 'https://github.com'
90101
const metascraper = createMetascraper()

0 commit comments

Comments
 (0)