fixes
This commit is contained in:
1 parent
3b0d692839
commit
8b540d22bc
14 files changed
+526
-82
No files matched your search
@@ -250,7 +250,12 @@ func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionF
|
||||
if isBuiltInMetaRoleBoilerplate(metaBody) {
|
||||
metaBody = ""
|
||||
}
|
||||
if strings.TrimSpace(out.MetaTitle) == "" && strings.TrimSpace(out.MetaDescription) == "" && strings.TrimSpace(metaBody) != "" {
|
||||
// Explicit language-scoped Meta instructions belong to the current language.
|
||||
// A shared JSON description_template may hold English default meta rules,
|
||||
// but must not override the translated --- Meta --- section in the API.
|
||||
if mt, md, ok := splitLocalizedMetaRules(metaBody); ok {
|
||||
out.MetaTitle, out.MetaDescription = mt, md
|
||||
} else if strings.TrimSpace(out.MetaTitle) == "" && strings.TrimSpace(out.MetaDescription) == "" && strings.TrimSpace(metaBody) != "" {
|
||||
out.MetaDescription = strings.TrimSpace(metaBody)
|
||||
out.MetaTitle = DefaultLegacyMetaTitleRule
|
||||
} else {
|
||||
@@ -264,6 +269,28 @@ func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionF
|
||||
return out
|
||||
}
|
||||
|
||||
// splitLocalizedMetaRules parses the two fixed schema keys while retaining the
|
||||
// instructions verbatim in the category's selected content language. The braces
|
||||
// are editor instruction delimiters, not text for SEO output.
|
||||
func splitLocalizedMetaRules(body string) (title, description string, ok bool) {
|
||||
body = strings.TrimSpace(body)
|
||||
if strings.HasPrefix(body, "{") && strings.HasSuffix(body, "}") &&
|
||||
!strings.HasPrefix(body, "{{") {
|
||||
body = strings.TrimSpace(body[1 : len(body)-1])
|
||||
}
|
||||
lower := strings.ToLower(body)
|
||||
if !strings.HasPrefix(lower, "meta_title:") {
|
||||
return "", "", false
|
||||
}
|
||||
idx := strings.Index(lower, "meta_description:")
|
||||
if idx < 0 {
|
||||
return "", "", false
|
||||
}
|
||||
title = strings.TrimSpace(body[len("meta_title:"):idx])
|
||||
description = strings.TrimSpace(body[idx+len("meta_description:"):])
|
||||
return title, description, title != "" && description != ""
|
||||
}
|
||||
|
||||
func isBuiltInMetaRoleBoilerplate(body string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(body))
|
||||
return strings.HasPrefix(lower, "role: meta")
|
||||
|
||||
Reference in new issue
Block a user