This commit is contained in:
2026-08-16 16:57:36 +02:00
parent 96f8c1115c
commit 532d439c41
106 changed files with 10147 additions and 494 deletions
+9 -5
View File
@@ -161,12 +161,11 @@ func ExtractProductImages(mapped, raw map[string]any) (main string, more []strin
break
}
}
if imgs, ok := merged["images"].([]any); ok && len(imgs) > 0 {
urls := coerceToURLList(imgs)
if main == "" && len(urls) > 0 {
if urls := coerceToURLList(merged["images"]); len(urls) > 0 {
if main == "" {
main = urls[0]
urls = urls[1:]
} else if len(urls) > 0 && urls[0] == main {
} else if urls[0] == main {
urls = urls[1:]
}
for _, u := range urls {
@@ -175,6 +174,11 @@ func ExtractProductImages(mapped, raw map[string]any) (main string, more []strin
}
}
}
// Feeds often leave main_image empty while moreimages/images hold URLs.
if main == "" && len(more) > 0 {
main = more[0]
more = more[1:]
}
if main != "" {
filtered := more[:0]
for _, u := range more {
@@ -211,7 +215,7 @@ func coerceToURLString(value any) string {
}
return ""
case map[string]any:
for _, k := range []string{"#text", "__cdata", "@_href", "@_url", "href", "url"} {
for _, k := range []string{"#text", "__cdata", "@_href", "@_url", "href", "url", "src", "link", "image"} {
if u := coerceToURLString(v[k]); u != "" {
return u
}