laurengarcia / url-metadata

NPM module: Request a url and scrape the metadata from its HTML using Node.js or the browser.
https://www.npmjs.com/package/url-metadata
MIT License
166 stars 43 forks source link

Support for links #73

Closed ajmas closed 7 months ago

ajmas commented 7 months ago

Is there any way to support link tags? The motivation is looking at http://news.bbc.co.uk where there is link tags are being used for the favicons. I am not seeing any other useful metadata for the favicons.

laurengarcia commented 7 months ago

Hi there. Thanks for this issue, i was able to reproduce it and ship somewhat of a fix for that page, but it appears to perhaps have some kind of malformed html issue. Was able to get correct behavior out of another link on the BBC site, so its probably just the home page. Sometimes these big sites have large CMS's and the home page can get messy.

If you pass in this url to the module you'll see correct behavior, it also now returns the apple-touch-icon, alternate icon & mask-icon (Safari pinned tab) in addition to the original icon tag(s): https://www.bbc.com/news/uk-england-somerset-68179350

The new version 3.4.8 has the changes you need: https://www.npmjs.com/package/url-metadata?activeTab=versions

I added some tricks to this package to make the BBC favicons on the homepage work better but it still unfortunately can't grab all the favicons, but it does grab some of them now. Here's what I'm seeing returned from the home page http://news.bbc.co.uk now:

    [
      {
        rel: 'apple-touch-icon-precomposed',
        type: undefined,
        href: '//m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.3.0/apple-touch-icon-57x57-precomposed.png',
        sizes: '57x57'
      },
      {
        rel: 'apple-touch-icon-precomposed',
        type: undefined,
        href: '//m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.3.0/apple-touch-icon-72x72-precomposed.png',
        sizes: '72x72'
      },
      {
        rel: 'apple-touch-icon-precomposed',
        type: undefined,
        href: '//m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.3.0/apple-touch-icon-114x114-precomposed.png',
        sizes: '114x114'
      },
      {
        rel: 'apple-touch-icon-precomposed',
        type: undefined,
        href: '//m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.3.0/apple-touch-icon.png',
        sizes: '144x144'
      },
      {
        rel: 'apple-touch-icon',
        type: undefined,
        href: '//m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.3.0/apple-touch-icon.png',
        sizes: undefined
      }
    ]
ajmas commented 7 months ago

Thank you. That was quick.