Skip to content

Commit

Permalink
fix(metascraper-logo-favicon): allow URL input and apply priority. cl…
Browse files Browse the repository at this point in the history
…oses #724
  • Loading branch information
aldenquimby committed Oct 2, 2024
1 parent 7a504f7 commit cfe41bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/metascraper-logo-favicon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const getDomNodeSizes = (domNodes, attr, url) =>
{
...domNode.attribs,
url: normalizedUrl,
size: getSize(url, domNode.attribs.sizes)
size: getSize(normalizedUrl, domNode.attribs.sizes)
}
]
}, [])
Expand Down Expand Up @@ -163,8 +163,8 @@ const createFavicon = (
const faviconUrl = logo(`/favicon.${ext}`, { url })
return faviconUrl
? resolveFaviconUrl(faviconUrl, contentTypes, gotOpts).then(
response => response?.url
)
response => response?.url
)
: undefined
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/metascraper-logo-favicon/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ test('get the biggest icon possible', async t => {
t.is(metadata.logo, 'https://cdn.microlink.io/logo/favicon-196x196.png')
})

test('prefers small png over large ico', async t => {
const url = 'https://github.com'
const metascraper = createMetascraper()
const html = createHtml([
'<link rel="icon" type="image/png" href="/fluidicon.png" sizes="96x96">',
'<link rel="icon" type="image/x-icon" href="/favicon.ico" sizes="128x128">'
])
const metadata = await metascraper({ url, html })
t.is(metadata.logo, 'https://github.com/fluidicon.png')
})

test('detect `rel="fluid-icon"`', async t => {
const url = 'https://github.com'
const metascraper = createMetascraper()
Expand Down

0 comments on commit cfe41bb

Please sign in to comment.