upddate
This commit is contained in:
1 parent
ff6c2df618
commit
43cfaa0411
18 files changed
+683
-299
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
var (
|
||||
reLegacyHTMLBlock = regexp.MustCompile(`(?is)<\s*(h[1-4]|p|ul|ol|li|b|strong)\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*(?:h[1-4]|p|ul|ol|li|b|strong)\s*>`)
|
||||
reLegacyList = regexp.MustCompile(`(?is)<\s*ul\s*>\s*<\s*li\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*li\s*>\s*<\s*/\s*ul\s*>`)
|
||||
reLegacyBoldUL = regexp.MustCompile(`(?is)<\s*b\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*b\s*>\s*<\s*ul\s*>\s*<\s*li\s*>\s*\{?\s*(.*?)\s*\}?\s*<\s*/\s*li\s*>\s*<\s*/\s*ul\s*>`)
|
||||
)
|
||||
|
||||
@@ -21,6 +22,7 @@ func LegacyHTMLFormulaPresent(s string) bool {
|
||||
type DescriptionFormulaSection struct {
|
||||
Type string `json:"type"`
|
||||
Instructions string `json:"instructions"`
|
||||
Optional bool `json:"optional,omitempty"`
|
||||
}
|
||||
|
||||
// DescriptionFormula is the JSON shape stored in categories.description_template
|
||||
@@ -59,11 +61,16 @@ const DefaultMetaTitleRuleEN = "Start with the New product name and add the main
|
||||
// title rule, so meta intent (MetaRules present) also seeds a default metaTitle
|
||||
// instruction — the category UI then shows all four prompt areas filled.
|
||||
func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) DescriptionFormula {
|
||||
out := DescriptionFormula{
|
||||
MetaDescription: strings.TrimSpace(parts.MetaRules),
|
||||
}
|
||||
out := DescriptionFormula{MetaDescription: strings.TrimSpace(parts.MetaRules)}
|
||||
if out.MetaDescription != "" {
|
||||
out.MetaTitle = DefaultLegacyMetaTitleRule
|
||||
// Current default prompts encode both SEO fields explicitly. Preserve
|
||||
// each role rather than nesting the title rule inside meta_description.
|
||||
meta := strings.TrimSpace(strings.Trim(out.MetaDescription, "{} "))
|
||||
if idx := strings.Index(meta, "\nmeta_description:"); idx > 0 && strings.HasPrefix(meta, "meta_title:") {
|
||||
out.MetaTitle = strings.TrimSpace(strings.TrimPrefix(meta[:idx], "meta_title:"))
|
||||
out.MetaDescription = strings.TrimSpace(meta[idx+len("\nmeta_description:"):])
|
||||
}
|
||||
}
|
||||
body := strings.TrimSpace(parts.DescriptionRules)
|
||||
if body == "" {
|
||||
@@ -74,7 +81,18 @@ func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) Descripti
|
||||
remaining := body
|
||||
for remaining != "" {
|
||||
boldUL := reLegacyBoldUL.FindStringSubmatchIndex(remaining)
|
||||
list := reLegacyList.FindStringSubmatchIndex(remaining)
|
||||
block := reLegacyHTMLBlock.FindStringSubmatchIndex(remaining)
|
||||
if list != nil && (block == nil || list[0] <= block[0]) && (boldUL == nil || list[0] < boldUL[0]) {
|
||||
m := reLegacyList.FindStringSubmatch(remaining[list[0]:list[1]])
|
||||
if len(m) > 1 {
|
||||
if instr := cleanLegacyInstruction(m[1]); instr != "" {
|
||||
out.Sections = append(out.Sections, DescriptionFormulaSection{Type: "ul", Instructions: instr, Optional: true})
|
||||
}
|
||||
}
|
||||
remaining = remaining[list[1]:]
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case boldUL != nil && (block == nil || boldUL[0] <= block[0]):
|
||||
m := reLegacyBoldUL.FindStringSubmatch(remaining[boldUL[0]:boldUL[1]])
|
||||
@@ -89,7 +107,7 @@ func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) Descripti
|
||||
instr = heading
|
||||
}
|
||||
if strings.TrimSpace(instr) != "" {
|
||||
out.Sections = append(out.Sections, DescriptionFormulaSection{Type: "ul", Instructions: instr})
|
||||
out.Sections = append(out.Sections, DescriptionFormulaSection{Type: "ul", Instructions: instr, Optional: true})
|
||||
}
|
||||
remaining = remaining[boldUL[1]:]
|
||||
case block != nil:
|
||||
@@ -112,6 +130,20 @@ func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) Descripti
|
||||
return out
|
||||
}
|
||||
}
|
||||
// The modern product-page formula has an introduction and optional
|
||||
// feature/specification blocks. If evidence is sparse, do not require the
|
||||
// model to hallucinate headings or empty paragraphs.
|
||||
if len(out.Sections) == 5 && out.Sections[0].Type == "p" &&
|
||||
out.Sections[1].Type == "h2" && out.Sections[2].Type == "p" &&
|
||||
out.Sections[3].Type == "h2" && out.Sections[4].Type == "ul" {
|
||||
out.Sections[1].Optional = true
|
||||
out.Sections[2].Optional = true
|
||||
}
|
||||
for i := 0; i+1 < len(out.Sections); i++ {
|
||||
if out.Sections[i].Type == "h2" && out.Sections[i+1].Type == "ul" {
|
||||
out.Sections[i].Optional = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user