fix(publisher): normalize FPA federation naming typos at publish (BIT-26494)
Replace wrong variants (Federação Portuguesa de Andebol, FPAndebol) with the official "Federação de Andebol de Portugal" in sanitizeArticleMeta. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
7262da3e9f
commit
aff9033c23
2 files changed
+49
-1
No files matched your search
@@ -20,6 +20,39 @@ const SKIP_NAME_FRAGMENTS = new Set([
|
||||
'fonte original', 'fonte federação'
|
||||
]);
|
||||
|
||||
const FPA_CANONICAL_NAME = 'Federação de Andebol de Portugal';
|
||||
|
||||
const FPA_NAME_SUBSTITUTIONS = [
|
||||
{ pattern: /\bFederação Portuguesa de Andebol\b/gi, replacement: FPA_CANONICAL_NAME },
|
||||
{ pattern: /\bFederacao Portuguesa de Andebol\b/gi, replacement: FPA_CANONICAL_NAME },
|
||||
{ pattern: /\bFPAndebol\b/g, replacement: FPA_CANONICAL_NAME },
|
||||
{ pattern: /\bFP\s+Andebol\b/gi, replacement: FPA_CANONICAL_NAME }
|
||||
];
|
||||
|
||||
function normalizeFederationNames(text) {
|
||||
let result = String(text || '');
|
||||
for (const { pattern, replacement } of FPA_NAME_SUBSTITUTIONS) {
|
||||
result = result.replace(pattern, replacement);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function normalizeArticleFederationNames(article) {
|
||||
const next = { ...article };
|
||||
for (const field of [
|
||||
'title', 'subtitle', 'summary', 'excerpt', 'body', 'content',
|
||||
'seo_title', 'seo_description'
|
||||
]) {
|
||||
if (next[field]) {
|
||||
next[field] = normalizeFederationNames(next[field]);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(next.tags)) {
|
||||
next.tags = next.tags.map((tag) => normalizeFederationNames(tag));
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function foldAccents(value) {
|
||||
return String(value || '')
|
||||
.normalize('NFD')
|
||||
@@ -223,7 +256,7 @@ function deriveFocusKeyword(article) {
|
||||
* @returns {Object} shallow copy with sanitized meta fields
|
||||
*/
|
||||
function sanitizeArticleMeta(article, siteConfig = {}) {
|
||||
const next = { ...article };
|
||||
const next = normalizeArticleFederationNames(article);
|
||||
const corpus = articleCorpus(article);
|
||||
const inferMode = siteConfig?.tags_infer || siteConfig?.category_infer;
|
||||
|
||||
@@ -249,5 +282,7 @@ module.exports = {
|
||||
tagMentionedInCorpus,
|
||||
plainTextFromHtml,
|
||||
articleCorpus,
|
||||
normalizeFederationNames,
|
||||
normalizeArticleFederationNames,
|
||||
ANDEBOL_ENTITY_RULES
|
||||
};
|
||||
@@ -50,3 +50,16 @@ test('sanitizeArticleMeta keeps valid LLM tags', () => {
|
||||
assert.ok(result.tags.includes('Sporting CP'));
|
||||
assert.equal(result.tags.includes('Pedro Santos'), false);
|
||||
});
|
||||
|
||||
test('sanitizeArticleMeta normalizes FPA federation naming typos', () => {
|
||||
const result = sanitizeArticleMeta({
|
||||
title: 'FPAndebol anuncia calendário',
|
||||
body: '<p>A Federação Portuguesa de Andebol confirmou o calendário.</p>',
|
||||
excerpt: 'Notícia da FP Andebol sobre competições nacionais.'
|
||||
}, { tags_auto: true });
|
||||
|
||||
assert.equal(result.title, 'Federação de Andebol de Portugal anuncia calendário');
|
||||
assert.ok(result.body.includes('Federação de Andebol de Portugal'));
|
||||
assert.ok(!result.body.includes('Federação Portuguesa de Andebol'));
|
||||
assert.ok(result.excerpt.includes('Federação de Andebol de Portugal'));
|
||||
});
|
||||
Reference in new issue
Block a user