Fix ICO icon is retrieved from Guardian instead of PNG icon (#178)

This commit is contained in:
Quang Lam 2020-03-29 17:35:55 +07:00 committed by GitHub
parent 2bdbc7b4b5
commit d05974e0dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,9 +20,12 @@ const getWebsiteIconUrlAsync = (websiteURL) => customizedFetch(websiteURL)
// find the icon with largest size
rootElm.each((i, _elm) => {
const elm = $(_elm);
// make sure icon is png
if (elm.attr('type') === 'image/png'
|| elm.attr('href').endsWith('.png')) {
// check if type is PNG
// also check to make sure links doesn't end with .ico
// as some websites specify icon type wrong
// see https://github.com/atomery/webcatalog/issues/630 for more details
if ((elm.attr('type') === 'image/png' && !elm.attr('href').endsWith('.ico'))
|| elm.attr('href').endsWith('.png')) { // if type is not specified but link ends with .png then assumes that the icon is PNG
const size = elm.attr('sizes') ? parseInt(elm.attr('sizes').split('x'), 10) : 0;
if (size >= maxSize) {
maxSize = size;