fix(favicon): enhance variant handling in GetFavIconFromAlias function

- Added fallback logic to handle cases where the requested icon variant is unavailable.
- If variant not provided, do not call WithVariant.
This commit is contained in:
yusing
2025-12-15 14:37:33 +08:00
parent d319ee99ad
commit f43e07fe60

View File

@@ -81,9 +81,14 @@ func GetFavIconFromAlias(ctx context.Context, alias string, variant homepage.Ico
if hp.Icon != nil {
if hp.Icon.IconSource == homepage.IconSourceRelative {
result, err = homepage.FindIcon(ctx, r, *hp.Icon.FullURL)
} else if variant != homepage.IconVariantNone {
result, err = homepage.FetchFavIconFromURL(ctx, hp.Icon.WithVariant(variant))
if err != nil {
// fallback to no variant
result, err = homepage.FetchFavIconFromURL(ctx, hp.Icon.WithVariant(homepage.IconVariantNone))
}
} else {
icon := hp.Icon.WithVariant(variant)
result, err = homepage.FetchFavIconFromURL(ctx, icon)
result, err = homepage.FetchFavIconFromURL(ctx, hp.Icon)
}
} else {
// try extract from "link[rel=icon]"