fixes
This commit is contained in:
1 parent
43cfaa0411
commit
3b0d692839
7 files changed
+341
-136
No files matched your search
@@ -145,17 +145,24 @@ func a1ReplaceTagContent(source string, expression *regexp.Regexp, newInstructio
|
||||
return source[:matches[4]] + newInstruction + source[matches[5]:]
|
||||
}
|
||||
|
||||
// isKnownA1Boilerplate only targets the old generated five-benefit formula.
|
||||
// User-authored copy (even if it contains multiple H2s) is never replaced.
|
||||
// isKnownA1Boilerplate recognizes the exact historical A1-generated
|
||||
// instructions, even when a previous cleanup left only one to three pairs.
|
||||
// Generic custom HTML with H2/P sections must never be replaced.
|
||||
func isKnownA1Boilerplate(body string, blocks int) bool {
|
||||
if blocks < 4 {
|
||||
if blocks < 1 {
|
||||
return false
|
||||
}
|
||||
lower := strings.ToLower(body)
|
||||
return (strings.Contains(lower, "napiši odstavek, ki je dolg 100 besed") ||
|
||||
strings.Contains(lower, "drugačno in preverjeno prednost") ||
|
||||
strings.Contains(lower, "napiši približno 100 besed o")) &&
|
||||
(strings.Contains(lower, "novo ime izdelka") || strings.Contains(lower, "prednost izdelka"))
|
||||
lower := strings.ToLower(a1Whitespace.ReplaceAllString(strings.TrimSpace(body), " "))
|
||||
legacy := strings.Contains(lower, "napiši odstavek, ki je dolg 100 besed")
|
||||
cableLegacy := strings.Contains(lower, "nadaljuj iz naslova in napiši 100 besed") &&
|
||||
strings.Contains(lower, "novo_ime_izdelka")
|
||||
if !legacy && !cableLegacy {
|
||||
return false
|
||||
}
|
||||
return (strings.Contains(lower, "novo ime izdelka") || strings.Contains(lower, "novo_ime_izdelka")) &&
|
||||
(strings.Contains(lower, "izpostavi en benefit") ||
|
||||
strings.Contains(lower, "prednost izdelka") ||
|
||||
strings.Contains(lower, "preverjeno prednost"))
|
||||
}
|
||||
|
||||
func localizedA1SEODescription() string {
|
||||
@@ -167,6 +174,7 @@ func localizedA1SEODescription() string {
|
||||
}
|
||||
|
||||
var a1SpecTrailing = regexp.MustCompile(`(?is)^\s*<\s*b\s*>.*?<\s*/\s*b\s*>\s*<\s*ul\s*>.*?<\s*/\s*ul\s*>`)
|
||||
var a1RedundantH1 = regexp.MustCompile(`(?is)<\s*h1\s*>\s*\{\s*zapiši\s+novo_ime_izdelka\s*\}\s*<\s*/\s*h1\s*>\s*`)
|
||||
|
||||
// upgradeKnownA1Boilerplate replaces only the recognizable generated legacy
|
||||
// five-benefit scaffold with short, factual HTML. The title/meta roles and
|
||||
@@ -182,18 +190,37 @@ func upgradeKnownA1Boilerplate(source string) (string, int) {
|
||||
}
|
||||
start, end := blocks[0][0], blocks[len(blocks)-1][1]
|
||||
if match := a1SpecTrailing.FindStringIndex(source[end:]); len(match) == 2 && match[0] == 0 {
|
||||
end += match[1]
|
||||
// Discard only the old generic spec instruction. A category-specific
|
||||
// technical specification rule must remain intact.
|
||||
trailing := strings.ToLower(source[end : end+match[1]])
|
||||
if strings.Contains(trailing, "napiši 3-10 tehničnih specifikacij") ||
|
||||
strings.Contains(trailing, "napiši 3–10 tehničnih specifikacij") {
|
||||
end += match[1]
|
||||
}
|
||||
}
|
||||
return source[:start] + html + source[end:], len(blocks)
|
||||
updated := source[:start] + html + source[end:]
|
||||
// Only the known imported A1 scaffold generates a redundant page H1.
|
||||
// The storefront already renders its own H1 from the product title.
|
||||
updated = a1RedundantH1.ReplaceAllString(updated, "")
|
||||
return updated, len(blocks)
|
||||
}
|
||||
|
||||
// upgradeKnownA1Sections is equally narrow for JSON description_template.
|
||||
// It retains the existing metaTitle/metaDescription and unknown JSON fields.
|
||||
func upgradeKnownA1Sections(raw string) (string, int, error) {
|
||||
// A1 categories frequently have no structured description_template.
|
||||
// The HTML prompt alone is valid; an empty JSON column isn't an error.
|
||||
trimmed := strings.TrimSpace(raw)
|
||||
if trimmed == "" || trimmed == "null" || trimmed == "{}" {
|
||||
return raw, 0, nil
|
||||
}
|
||||
var obj map[string]json.RawMessage
|
||||
if err := json.Unmarshal([]byte(raw), &obj); err != nil {
|
||||
return raw, 0, err
|
||||
}
|
||||
if len(obj) == 0 || len(obj["sections"]) == 0 || string(obj["sections"]) == "null" {
|
||||
return raw, 0, nil
|
||||
}
|
||||
var sections []DescriptionFormulaSection
|
||||
if err := json.Unmarshal(obj["sections"], §ions); err != nil {
|
||||
return raw, 0, nil
|
||||
@@ -263,8 +290,9 @@ func NormalizeA1RepeatedBenefits(source string) (string, int) {
|
||||
return out.String(), rewritten
|
||||
}
|
||||
|
||||
// NormalizeA1DescriptionTemplate applies the same non-repeating benefit rules
|
||||
// to the structured A1 description editor sections. No sections are deleted.
|
||||
// NormalizeA1DescriptionTemplate upgrades recognizable imported A1 description
|
||||
// boilerplate to the semantic SEO sections. For unrelated custom descriptions,
|
||||
// only repeated instructions are rewritten and sections remain intact.
|
||||
func NormalizeA1DescriptionTemplate(raw string) (string, int, error) {
|
||||
if cleaned, n, err := upgradeKnownA1Sections(raw); err != nil || n > 0 {
|
||||
return cleaned, n, err
|
||||
|
||||
Reference in new issue
Block a user