fixes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user