Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e8d81a0cb |
No files matched your search
@@ -197,12 +197,29 @@ function fill(template: string, vars: TemplateVars, codes: CodeList | undefined,
|
||||
return expanded.text;
|
||||
}
|
||||
|
||||
/** Collapse the spaces an empty variable leaves behind. Missing variables are always reported as issues. */
|
||||
/**
|
||||
* Collapse the holes an empty variable leaves behind. Missing variables are always reported as issues.
|
||||
* The newsroom caption is "{event}, em {city}, no {venue}": without city/venue that must not become
|
||||
* "AFS x FC Vizela, em , no" on a client delivery.
|
||||
*/
|
||||
function tidy(value: string): string {
|
||||
// A match template on an event without an away team: "Gala x , em Braga" → "Gala, em Braga".
|
||||
return value
|
||||
.replace(/\s{2,}/g, " ")
|
||||
// Match template on an event without an away team: "Gala x , em Braga" → "Gala, em Braga".
|
||||
.replace(/\s+x\s*(?=,|$)/g, "")
|
||||
// City missing, venue kept: ", em , no Estádio" → ", no Estádio" (keep the article).
|
||||
.replace(/,\s*em\s*,\s*(n[oa]s?\s+)/gi, ", $1")
|
||||
// Both city and venue missing: trailing ", em , no" / ", em , na".
|
||||
.replace(/,\s*em\s*,\s*n[oa]s?\s*$/gi, "")
|
||||
// Leftover empty city slot: ", em ,".
|
||||
.replace(/,\s*em\s*,/gi, ",")
|
||||
// Venue missing at the end: ", em Braga, no" → ", em Braga".
|
||||
.replace(/,\s*n[oa]s?\s*$/gi, "")
|
||||
// Orphan "em" at the end: ", em".
|
||||
.replace(/,\s*em\s*$/gi, "")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.replace(/,\s*$/g, "")
|
||||
.replace(/^\s*,\s*/g, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,30 @@ describe("IPTC template", () => {
|
||||
expect(old.event).toBe("Conferência de imprensa do FC Porto");
|
||||
});
|
||||
|
||||
it("does not send a broken Portuguese caption when city and venue are missing", () => {
|
||||
// Delivered to Cofina as "AFS x FC Vizela, em , no" — unusable in the newsroom.
|
||||
const game = { home: "AFS", away: "FC Vizela", venue: "", city: "", sport: "futebol", startsAt: new Date("2026-11-04T20:00:00Z") };
|
||||
const { values, issues } = applyTemplate(NEWSROOM_TEMPLATE, buildVars(game, { players: ["Rodrigo Pinho"] }, "MovePhoto"));
|
||||
expect(values.caption).toBe("AFS x FC Vizela");
|
||||
expect(values.headline).toBe("AFS x FC Vizela");
|
||||
expect(values.event).toBe("AFS x FC Vizela");
|
||||
expect(values.city).toBeUndefined();
|
||||
expect(values.location).toBeUndefined();
|
||||
expect(issues.filter((i) => i.kind === "missing_variable").map((i) => i.detail).sort()).toEqual([
|
||||
"city",
|
||||
"city",
|
||||
"city",
|
||||
"venue",
|
||||
"venue",
|
||||
"venue",
|
||||
]);
|
||||
// Only one of city / venue filled: keep the clause that still makes sense.
|
||||
expect(applyTemplate(NEWSROOM_TEMPLATE, buildVars({ ...game, city: "Vizela" }, {}, "P")).values.caption).toBe("AFS x FC Vizela, em Vizela");
|
||||
expect(applyTemplate(NEWSROOM_TEMPLATE, buildVars({ ...game, venue: "Estádio do FC Vizela" }, {}, "P")).values.caption).toBe(
|
||||
"AFS x FC Vizela, no Estádio do FC Vizela",
|
||||
);
|
||||
});
|
||||
|
||||
it("expands codes typed by an editor and keeps long venues whole", () => {
|
||||
const { values, issues } = applyTemplate({ title: "\\v7\\", location: "{venue}" }, buildVars(braga), codeList({ v7: "Miguel Silva (VSC)" }));
|
||||
expect(values.title).toBe("Miguel Silva (VSC)");
|
||||
|
||||
Reference in new issue
Block a user