FaviconFinder icon indicating copy to clipboard operation
FaviconFinder copied to clipboard

Support sites with multiple favicon resolutions

Open daprice opened this issue 2 years ago • 1 comments

It’s pretty common for sites to offer multiple resolutions of each favicon type – for example https://mastodon.social/ has 11 different sizes of apple-touch-icon and 3 of icon.

It’s not clear which one FaviconFinder returns or if there’s any way to control it. For mastodon.social it looks like it gives me the largest available icon but the smallest apple-touch-icon. I’d love to be able to either:

  • specify the ideal size I want and get the closest available one, and/or
  • have FaviconFinder return all available URLs along with the value of the sizes HTML attribute so I can use them dynamically based on the size of my views.

daprice avatar Oct 25 '23 22:10 daprice

Hey @daprice! Thanks for getting in touch. This is a great point and an oversight on my behalf. I'll be looking to implement this over the next week or so.

will-lumley avatar Oct 27 '23 23:10 will-lumley

Hey @daprice - just want to reach out and apologise for not getting onto this earlier. Looking at this now and will post any updates here.

will-lumley avatar Feb 06 '24 10:02 will-lumley

No worries @will-lumley, I’m just thankful this exists at all!

daprice avatar Feb 07 '24 23:02 daprice

My pleasure @daprice. Just to keep you in the loop, tonight FaviconFinder 5.0.0 will come out.

Significant refactoring has occurred for its internals, and it also has a much more developer-friendly API (in my opinion at least). You'll be able to grab all the Favicon's for a specified source, choose to download them if you want, and you can get the largest image by default, or the smallest, etc. The sizes for all the images fetched will also be a part of a property so you can tell for what sized view they might be most appropriate for.

I'll link the PR to this issue so you get a notification for it and can see when it's available :)

will-lumley avatar Feb 09 '24 05:02 will-lumley

@daprice The PR is up. Once this PR is merged, you can get an array of FaviconURLs for a particular URL. This is what a FaviconURL looks like.

public struct FaviconURL {
    /// The url of the .ico or HTML page, of where the favicon was found
    public let source: URL

    /// The type of favicon we extracted
    public let format: FaviconFormatType

    /// The source type of the favicon we extracted
    public let sourceType: FaviconSourceType

    /// If the icon is from HTML/WAMF and we've been told it's size, we'll store that data here
    public let sizeTag: String?
}

If the HTML tag has it listed, the sizeTag property will have whatever was in the HTML for that particular icon. This should help you determine what size the image should be used for.

Would love to hear your thoughts.

will-lumley avatar Feb 11 '24 07:02 will-lumley

This issue is closed because the PR is merged - but feel free to post any thoughts you have here still :)

will-lumley avatar Feb 11 '24 09:02 will-lumley

Thanks, this is great! Including the sizeTag gives me all the flexibility I could ask for.

One minor documentation issue: the docs say FaviconURL.source is the URL of the page where it was found, but it looks like it’s actually the URL of the favicon image file itself? In my case the URL of the image file is what I need, so it works as is, but it’s not what the docs say unless I’m misunderstanding something.

daprice avatar Feb 20 '24 23:02 daprice