Skip to content

Commit 403ee80

Browse files
committed
style: strip leading numbering from preview text before title deduplication
1 parent 7922dea commit 403ee80

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

apps/desktop/src/features/dashboard/lib/strip-title-from-preview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export function stripTitleFromPreview(title: string, summary: string): string {
99

1010
const stripped = stripMarkdown(summary);
1111
const normalizedTitle = title.replace(/\s+/g, " ").trim().toLowerCase();
12-
const normalizedStripped = stripped.replace(/\s+/g, " ").trim();
12+
13+
// Strip leading list numbering (e.g. "1) ", "2. ") to match cleanArtifactTitle behavior
14+
const withoutNumbering = stripped.replace(/^\d+[.)]\s+/, "");
15+
16+
const normalizedStripped = withoutNumbering.replace(/\s+/g, " ").trim();
1317
const normalizedStrippedLower = normalizedStripped.toLowerCase();
1418

1519
if (normalizedTitle && normalizedStrippedLower.startsWith(normalizedTitle)) {

test/ui/strip-title-from-preview.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { readFileSync, existsSync } from "node:fs";
33
import { resolve } from "node:path";
4+
import { stripTitleFromPreview } from "../../apps/desktop/src/features/dashboard/lib/strip-title-from-preview";
45

56
const utilPath = resolve(
67
__dirname,
@@ -51,6 +52,54 @@ describe("strip-title-from-preview utility", () => {
5152
});
5253
});
5354

55+
describe("stripTitleFromPreview — behavioral", () => {
56+
it("returns empty string for empty summary", () => {
57+
expect(stripTitleFromPreview("Some title", "")).toBe("");
58+
});
59+
60+
it("strips title prefix from summary", () => {
61+
expect(
62+
stripTitleFromPreview(
63+
"Feature matrix",
64+
"Feature matrix with grouped rows by use case",
65+
),
66+
).toBe("with grouped rows by use case");
67+
});
68+
69+
it("returns full summary when title is not a prefix", () => {
70+
expect(
71+
stripTitleFromPreview("Unrelated title", "Some preview text here"),
72+
).toBe("Some preview text here");
73+
});
74+
75+
it("strips leading numbering from preview before title comparison", () => {
76+
expect(
77+
stripTitleFromPreview(
78+
"Rewritten Free vs Pro feature matrix with grouped rows by",
79+
"1) Rewritten Free vs Pro feature matrix with grouped rows by use case > Important framing",
80+
),
81+
).toBe("use case > Important framing");
82+
});
83+
84+
it("strips '2. ' numbering prefix from preview before title comparison", () => {
85+
expect(
86+
stripTitleFromPreview(
87+
"Updated homepage hero copy",
88+
"2. Updated homepage hero copy: new version with better CTA",
89+
),
90+
).toBe("new version with better CTA");
91+
});
92+
93+
it("handles preview without numbering as before", () => {
94+
expect(
95+
stripTitleFromPreview(
96+
"SEO Audit Key Findings",
97+
"SEO Audit Key Findings — detailed breakdown follows",
98+
),
99+
).toBe("detailed breakdown follows");
100+
});
101+
});
102+
54103
describe("ArtifactCard title-echo removal", () => {
55104
it("ArtifactCard imports stripTitleFromPreview", () => {
56105
const src = readFileSync(artifactCardPath, "utf-8");

0 commit comments

Comments
 (0)