Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(branding): merge hyphen and underscore spellings of one font family (#5254)

Abimael Martell650ec6585a3f
diff --git a/apps/api/src/__tests__/lib/branding/jev.test.ts b/apps/api/src/__tests__/lib/branding/jev.test.ts
index 6d5612fb1..9b2d76eb0 100644
--- a/apps/api/src/__tests__/lib/branding/jev.test.ts
+++ b/apps/api/src/__tests__/lib/branding/jev.test.ts
@@ -618,7 +618,6 @@ describe("branding with Jev", () => {
expect(request.fonts.map(f => [f.family, f.role])).toEqual([
["Inter", "body"],
["Cormorant Garamond", "heading"],
- ["Open-Sans", undefined],
["Open Sans", undefined],
]);
});
@@ -996,6 +995,19 @@ describe("Jev request building", () => {
{ family: "Cormorant Garamond", count: 15, role: undefined },
]);
});
+
+ it("merges hyphen and underscore spellings of one family", () => {
+ const input = baseInput(new CostTracking());
+ input.jsAnalysis.typography = { fontFamilies: { primary: "Adobe-Clean" } };
+ input.jsAnalysis.fonts = [
+ { family: "Adobe-Clean", count: 12 },
+ { family: "Adobe Clean", count: 8 },
+ { family: "Adobe_Clean", count: 1 },
+ ];
+ expect(buildJevRequest(input).fonts).toEqual([
+ { family: "Adobe Clean", count: 21, role: "body" },
+ ]);
+ });
});
describe("branding metrics", () => {
diff --git a/apps/api/src/lib/branding/jev.ts b/apps/api/src/lib/branding/jev.ts
index b0375576c..8c3d2f551 100644
--- a/apps/api/src/lib/branding/jev.ts
+++ b/apps/api/src/lib/branding/jev.ts
@@ -297,7 +297,10 @@ type FontRole = BrandingEnhancement["cleanedFonts"][number]["role"];
type FontCandidate = { family: string; count: number; role?: FontRole };
/** Matching key for a family: case and spacing don't make a different font. */
-const familyKey = (family: string) => family.toLowerCase().replace(/\s/g, "");
+// Spacing, hyphen and underscore variants ("Adobe Clean", "Adobe-Clean",
+// "AdobeClean") are one family: pages self-host a face under a hyphenated alias.
+const familyKey = (family: string) =>
+ family.toLowerCase().replace(/[\s_-]/g, "");
/** Role from the page's own typography: the heading and body stacks it measured. */
function typographyRole(