From b807ef20c09aaf7ecec2c4e8e09322ecebc22997 Mon Sep 17 00:00:00 2001 From: awaae <108462724+awaae001@users.noreply.github.com> Date: Fri, 23 Oct 2026 23:40:33 +0900 Subject: [PATCH] fix(static): dynamically resolve manifest icon type and sizes (#3197) * fix(static): dynamically resolve manifest icon type and sizes - Add `omitempty` JSON tags to `ManifestIcon`'s `Sizes` and `Type` fields. - Introduce `manifestIcon` helper to detect MIME type from the icon URL path. - Set `Sizes` to "any" when the icon MIME type is SVG (`image/svg+xml`). - Update `ManifestJSON` handler to construct manifest icons dynamically instead of hardcoding PNG attributes. * fix(server): set default sizes to any for all manifest icons --- server/static/static.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/server/static/static.go b/server/static/static.go index 38eee2df..200dc397 100644 --- a/server/static/static.go +++ b/server/static/static.go @@ -7,6 +7,7 @@ import ( "io" "io/fs" "net/http" + "net/url" "os" "strings" @@ -20,8 +21,8 @@ import ( type ManifestIcon struct { Src string `json:"src"` - Sizes string `json:"sizes"` - Type string `json:"type"` + Sizes string `json:"sizes,omitempty"` + Type string `json:"type,omitempty"` } type Manifest struct { @@ -131,6 +132,19 @@ func UpdateIndex() { utils.Log.Debug("Index.html update completed") } +func manifestIcon(src string) ManifestIcon { + icon := ManifestIcon{Src: src, Sizes: "any"} + u, err := url.Parse(src) + if err != nil { + return icon + } + mimeType := utils.GetMimeType(u.Path) + if strings.HasPrefix(mimeType, "image/") { + icon.Type = mimeType + } + return icon +} + func ManifestJSON(c *gin.Context) { // Get site configuration to ensure consistent base path handling siteConfig := getSiteConfig() @@ -156,13 +170,7 @@ func ManifestJSON(c *gin.Context) { Scope: scope, StartURL: startURL, Name: siteTitle, - Icons: []ManifestIcon{ - { - Src: logoUrl, - Sizes: "512x512", - Type: "image/png", - }, - }, + Icons: []ManifestIcon{manifestIcon(logoUrl)}, } c.Header("Content-Type", "application/json")