Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metascraper-logo-favicon should prioritize png over ico and allow URL input #724

Closed
2 tasks done
aldenquimby opened this issue Oct 2, 2024 · 0 comments · Fixed by #726
Closed
2 tasks done

metascraper-logo-favicon should prioritize png over ico and allow URL input #724

aldenquimby opened this issue Oct 2, 2024 · 0 comments · Fixed by #726

Comments

@aldenquimby
Copy link
Contributor

aldenquimby commented Oct 2, 2024

Prerequisites

  • I'm using the last version.
  • My node version is the same as declared as package.json.

Subject of the issue

Two related issues:

  1. metascraper-logo-favicon should prioritize png over ico. basically this code should be running:

    // lets consider apple icon is beauty
    if (url.includes('apple')) return 5 * width
    if (url.includes('android')) return 5 * width
    if (url.endsWith('png')) return 5 * width
    if (url.endsWith('jpg') || url.endsWith('jpeg')) return 4 * width
    if (url.endsWith('svg')) return 3 * width
    if (url.endsWith('ico')) return 2 * width
    return 1 * width

  2. metascraper-logo-favicon should not fail with "url.match is not a function" when URL is supplied instead of string

    • metascraper, metascraper-title, metascraper-image, and metascraper-description all work with URL or string as input

Steps to reproduce

  • use metascraper-logo-favicon with any URL:
import createMetascraper from 'metascraper';
import metascraperLogoFavicon from 'metascraper-logo-favicon';

const url = new URL('https://github.com');
const html = await fetch(url).then(r => r.text());

const metascraper = createMetascraper([metascraperLogoFavicon()]);
const result = await metascraper({ html, url });

Note: You can reproduce the code using interactive Node.js shell by Runkit.

Expected behaviour

  • metascraper returns the favicon

Actual behaviour

  • metascraper throws this error:
TypeError: url.match is not a function
    at getSize (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:66:20)
    at eval (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:82:17)
    at arrayReduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:698:21)
    at Function.reduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:9750:14)
    at eval (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:4431:28)
    at arrayReduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:698:21)
    at baseWrapperValue (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:4430:14)
    at LodashWrapper.wrapperValue (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:9115:14)
    at getDomNodeSizes (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:86:6)
    at eval (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:92:26)
    at arrayReduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:698:21)
    at Function.reduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:9750:14)
    at eval (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:4431:28)
    at arrayReduce (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:698:21)
    at baseWrapperValue (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:4430:14)
    at LodashWrapper.wrapperValue (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:9115:14)
    at getSizes (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:94:6)
    at eval (webpack-internal:///(rsc)/../../node_modules/metascraper-logo-favicon/src/index.js:244:23)
    at eval (webpack-internal:///(rsc)/../../node_modules/@metascraper/helpers/index.js:444:29)
    at findRule (webpack-internal:///(rsc)/../../node_modules/@metascraper/helpers/index.js:434:35)
    at eval (webpack-internal:///(rsc)/../../node_modules/metascraper/src/get-data.js:11:27)
    at arrayMap (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:654:23)
    at map (webpack-internal:///(rsc)/../../node_modules/lodash/lodash.js:9623:14)
    at getData (webpack-internal:///(rsc)/../../node_modules/metascraper/src/get-data.js:10:5)
    at eval (webpack-internal:///(rsc)/../../node_modules/metascraper/src/index.js:29:12)

Tech Notes

@aldenquimby aldenquimby changed the title metascraper-logo-favicon should not fail with "url.match is not a function" metascraper-logo-favicon should allow URL input Oct 2, 2024
aldenquimby added a commit to aldenquimby/metascraper that referenced this issue Oct 2, 2024
@aldenquimby aldenquimby changed the title metascraper-logo-favicon should allow URL input metascraper-logo-favicon should prioritize png over ico and allow URL input Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant