fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -148,3 +149,58 @@ func metaBrandFromAttrs(bags ...map[string]any) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// metaFieldsFromEnhanceObj extracts plain SEO meta from an enhance JSON object.
|
||||
// Accepts snake_case and camelCase keys (legacy A1 <metaDescription> / cats.json).
|
||||
// Strips HTML and rejects prompt-leakage titles; empty when missing.
|
||||
func metaFieldsFromEnhanceObj(obj map[string]any) (title, description string) {
|
||||
if obj == nil {
|
||||
return "", ""
|
||||
}
|
||||
title = strings.TrimSpace(SanitizeOutput(fmt.Sprint(obj["meta_title"])))
|
||||
if title == "" || title == "<nil>" {
|
||||
title = strings.TrimSpace(SanitizeOutput(fmt.Sprint(obj["metaTitle"])))
|
||||
}
|
||||
description = strings.TrimSpace(SanitizeOutput(fmt.Sprint(obj["meta_description"])))
|
||||
if description == "" || description == "<nil>" {
|
||||
description = strings.TrimSpace(SanitizeOutput(fmt.Sprint(obj["metaDescription"])))
|
||||
}
|
||||
if title == "<nil>" {
|
||||
title = ""
|
||||
}
|
||||
if description == "<nil>" {
|
||||
description = ""
|
||||
}
|
||||
title = stripMetaTags(title)
|
||||
description = stripMetaTags(description)
|
||||
if isPromptLabelTitle(title) || isPromptLeakageTitle(title) {
|
||||
title = ""
|
||||
}
|
||||
if isPromptLabelTitle(description) || isPromptLeakageTitle(description) {
|
||||
description = ""
|
||||
}
|
||||
if title != "" {
|
||||
title = truncateMetaRunes(title, metaTitleMaxChars)
|
||||
}
|
||||
if description != "" {
|
||||
description = truncateMetaDescription(description, metaDescriptionMaxChars)
|
||||
}
|
||||
return title, description
|
||||
}
|
||||
|
||||
// enhanceMetaFromRaw reads meta_title / meta_description stashed on enhance raw meta.
|
||||
func enhanceMetaFromRaw(raw any) (title, description string) {
|
||||
m, ok := raw.(map[string]any)
|
||||
if !ok || m == nil {
|
||||
return "", ""
|
||||
}
|
||||
title = strings.TrimSpace(fmt.Sprint(m["meta_title"]))
|
||||
description = strings.TrimSpace(fmt.Sprint(m["meta_description"]))
|
||||
if title == "<nil>" {
|
||||
title = ""
|
||||
}
|
||||
if description == "<nil>" {
|
||||
description = ""
|
||||
}
|
||||
return title, description
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user