Skip to content

Commit

Permalink
refactor(logo-favicon): follow redirect & check content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 7, 2023
1 parent 3e4f740 commit 5b9f242
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/metascraper-logo-favicon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ const createGetLogo = ({ gotOpts, keyvOpts }) => {
const faviconUrl = logo('/favicon.ico', { url })
if (!faviconUrl) return

let response = await reachableUrl(faviconUrl, {
...gotOpts,
followRedirect: false
})
let response = await reachableUrl(faviconUrl, gotOpts)

if (response.statusCode >= 200 && response.statusCode < 300) {
if (
reachableUrl.isReachable(response) &&
response.headers['content-type']?.startsWith('image')
) {
return faviconUrl
}

Expand Down
4 changes: 2 additions & 2 deletions packages/metascraper-logo-favicon/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ test('resolve logo using favicon associated with the domain', async t => {
t.is(metadata.logo, 'https://teslahunt.io/favicon.ico')
})

test('resolve logo using favicon should be 2xx status code', async t => {
test('resolve logo using favicon should be an image content-type', async t => {
const url = 'https://vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ url })
t.true(metadata.logo.includes('gstatic'))
})

test('resolve logo using from google associated with the domain', async t => {
const url = 'https://escritopor.elenatorro.com'
const url = 'https://vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ url })
t.true(metadata.logo.includes('gstatic'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev).
description: 'Want to get more Likes on Facebook in 2021? No problem. To increase Likes on your FB page, you need to boost Likes on your FB posts. Here’s how to do that.',
image: 'https://www.postplanner.com/hubfs/blog/11_Ways_to_Get_Lots_of_Likes_on_Facebook_(the_right_way)/11%20Ways%20to%20Get%20Lots%20of%20Likes%20on%20Facebook%20(the%20right%20way!!)%20hero.png#keepProtocol',
lang: null,
logo: 'https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://www.postplanner.com/get-more-likes-fans-facebook-page/&size=128',
logo: 'https://www.postplanner.com/favicon.ico',
publisher: 'Post Planner',
title: 'Here’s How to Get More Likes on Facebook in 2021 (and Reach Millions)',
url: 'https://www.postplanner.com/get-more-likes-fans-facebook-page/',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ test('segment-academy', async t => {
const html = await readFile(resolve(__dirname, 'input.html'))
const { logo, ...metadata } = await metascraper({ html, url })
t.snapshot(metadata)
t.true(logo.includes('gstatic'))
})

0 comments on commit 5b9f242

Please sign in to comment.