Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions internal/app/card_manifest_deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ func cardManifestItemBody(item cardManifestItem, maxRunes int) string {
summary, impact := cardManifestFitSummaryImpact(item.Summary, item.Impact, maxRunes)
parts := make([]string, 0, 2)
if summary != "" {
parts = append(parts, "摘要:"+summary)
parts = append(parts, cardManifestLabelPrefix("摘要")+summary)
}
if impact != "" {
parts = append(parts, "影响:"+impact)
parts = append(parts, cardManifestLabelPrefix("影响")+impact)
}
return strings.Join(parts, "\n\n")
}
Expand Down Expand Up @@ -279,7 +279,11 @@ func cardManifestSectionText(section cardManifestBodySection) string {
if section.Label == "" {
return section.Body
}
return section.Label + ":" + section.Body
return cardManifestLabelPrefix(section.Label) + section.Body
}

func cardManifestLabelPrefix(label string) string {
return "**" + label + ":** "
}

func cardManifestSectionsFixedRuneCount(sections []cardManifestBodySection) int {
Expand All @@ -289,7 +293,7 @@ func cardManifestSectionsFixedRuneCount(sections []cardManifestBodySection) int
count += runeCount("\n\n")
}
if section.Label != "" {
count += runeCount(section.Label + ":")
count += runeCount(cardManifestLabelPrefix(section.Label))
}
}
return count
Expand Down Expand Up @@ -349,15 +353,15 @@ func cardManifestFitSummaryImpact(summary string, impact string, maxRunes int) (
return "", ""
}
if summary == "" {
impactBudget := maxRunes - runeCount("影响:")
impactBudget := maxRunes - runeCount(cardManifestLabelPrefix("影响"))
return "", cardManifestFitText(impact, impactBudget)
}
if impact == "" {
summaryBudget := maxRunes - runeCount("摘要:")
summaryBudget := maxRunes - runeCount(cardManifestLabelPrefix("摘要"))
return cardManifestFitText(summary, summaryBudget), ""
}

contentBudget := maxRunes - runeCount("摘要\n\n影响:")
contentBudget := maxRunes - runeCount(cardManifestLabelPrefix("摘要")+"\n\n"+cardManifestLabelPrefix("影响"))
if contentBudget < 2 {
return "", ""
}
Expand Down Expand Up @@ -392,10 +396,10 @@ func cardManifestBodyRuneCount(summary string, impact string) int {
func cardManifestBodyText(summary string, impact string) string {
parts := make([]string, 0, 2)
if summary != "" {
parts = append(parts, "摘要:"+summary)
parts = append(parts, cardManifestLabelPrefix("摘要")+summary)
}
if impact != "" {
parts = append(parts, "影响:"+impact)
parts = append(parts, cardManifestLabelPrefix("影响")+impact)
}
return strings.Join(parts, "\n\n")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestServiceGeneratePreviewBuildsCardManifestDeckWithoutAI(t *testing.T) {
if imagePage.Variant != "image-caption" || imagePage.Content.Title != "OpenAI 发布新模型" {
t.Fatalf("image page = %#v", imagePage)
}
if imagePage.Content.Body != "摘要:模型能力提升。\n\n影响:应用开发门槛下降。" {
if imagePage.Content.Body != "**摘要:** 模型能力提升。\n\n**影响:** 应用开发门槛下降。" {
t.Fatalf("image page body = %q", imagePage.Content.Body)
}
if imagePage.Meta.CTA != "来源:The Verge / 2026-06-16 11:00" {
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestServiceGeneratePreviewBuildsCardManifestSectionsWithoutSummaryImpactLab
t.Fatalf("GeneratePreview() error = %v", err)
}
body := r.rendered.Pages[1].Content.Body
want := "内容概览:这是一段海底生存游戏实况解说。\n\n互动数据:点赞 12,345|收藏 6,789|投币 2,345"
want := "**内容概览:** 这是一段海底生存游戏实况解说。\n\n**互动数据:** 点赞 12,345|收藏 6,789|投币 2,345"
if body != want {
t.Fatalf("section body = %q, want %q", body, want)
}
Expand Down