Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08056a8625 | ||
|
|
f11519f877 | ||
|
|
64720ef92e | ||
|
|
6bb960f053 | ||
|
|
5ef67f115f | ||
|
|
b54cfcae39 | ||
|
|
44ba50bd31 | ||
|
|
d90ccdeba0 | ||
|
|
b1bb4279fd | ||
|
|
7020d88776 | ||
|
|
7093619a0a | ||
|
|
0587a32529 | ||
|
|
067b1ae0f6 | ||
|
|
aff9033c23 | ||
|
|
4ed62556ee | ||
|
|
7262da3e9f | ||
|
|
b165de0811 | ||
|
|
7d04eec305 | ||
|
|
8f4575169d | ||
|
|
0818dfd0d4 | ||
|
|
451cd5afba | ||
|
|
22263b933e |
No files matched your search
@@ -83,6 +83,12 @@ QUEUE_MAX_DEPTH=5
|
||||
# PIPELINE_ALERT_WEBHOOK_URL=
|
||||
# PIPELINE_ALERT_WEBHOOK_TIMEOUT_MS=4000
|
||||
|
||||
# Error hub ingest (errors.bitreport.pt) — vault only; leave empty in Git examples
|
||||
# ERROR_REPORTING_ENDPOINT=https://errors.bitreport.pt
|
||||
# ERROR_REPORTING_TOKEN=
|
||||
ERROR_REPORTING_PROJECT_SLUG=ai-news-writer
|
||||
ERROR_REPORTING_GITEA_REPO=BitReport.pt/ai-news-writer
|
||||
|
||||
# Writing style — optional overrides (defaults come from config/writing-style.example.json)
|
||||
# WRITING_STYLE_CONFIG_PATH=
|
||||
# WRITING_TONE=
|
||||
|
||||
+4
-4
@@ -2,11 +2,11 @@
|
||||
# Replace/add owners as needed per repository domain.
|
||||
|
||||
# CI and forge metadata
|
||||
/.gitea/ @tiago-neves @david-santos
|
||||
/.gitea/workflows/ @tiago-neves @david-santos
|
||||
/.gitea/ @devops-engineer @founding-engineer
|
||||
/.gitea/workflows/ @devops-engineer @founding-engineer
|
||||
|
||||
# Documentation
|
||||
/docs/ @david-santos @planner
|
||||
/docs/ @founding-engineer
|
||||
|
||||
# Catch-all
|
||||
* @david-santos
|
||||
* @founding-engineer
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
run: npm ci
|
||||
|
||||
- name: Security audit
|
||||
run: npm audit --audit-level=high
|
||||
run: npm audit --omit=dev --audit-level=high
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
"category_default": 1,
|
||||
"category_infer": "andebol",
|
||||
"category_map": {
|
||||
"nacional": 1,
|
||||
"internacional": 2,
|
||||
"selecao": 3,
|
||||
"clubes": 4,
|
||||
"competicoes": 5,
|
||||
"resultados": 6
|
||||
"nacional": 8,
|
||||
"internacional": 9,
|
||||
"selecao": 10,
|
||||
"clubes": 11,
|
||||
"competicoes": 12,
|
||||
"resultados": 13
|
||||
},
|
||||
"status_default": "publish",
|
||||
"tags_auto": true,
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "andebol.net",
|
||||
"writing_tone": "formal",
|
||||
"audience_level": "general",
|
||||
"wp_transport": "rest",
|
||||
"wp_url": "https://andebol.net",
|
||||
"site_domain": "andebol.net",
|
||||
"category_default": 1,
|
||||
"category_infer": "andebol",
|
||||
"category_map": {
|
||||
"nacional": 8,
|
||||
"internacional": 9,
|
||||
"selecao": 10,
|
||||
"clubes": 11,
|
||||
"competicoes": 12,
|
||||
"resultados": 13
|
||||
},
|
||||
"status_default": "publish",
|
||||
"tags_auto": true,
|
||||
"tags_infer": "andebol",
|
||||
"lang": "pt"
|
||||
}
|
||||
+13
-6
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"rss": [
|
||||
{ "name": "FAP", "url": "https://portal.fpa.pt/feed/", "category": "andebol", "lang": "pt" },
|
||||
{ "name": "Handball Planet", "url": "https://www.handball-planet.com/feed/", "category": "andebol", "lang": "en" },
|
||||
{ "name": "IHF", "url": "https://www.ihf.info/rss.xml", "category": "andebol", "lang": "en" },
|
||||
{ "name": "Record", "url": "https://www.record.pt/rss", "category": "sports", "lang": "pt" },
|
||||
{ "name": "RTP Notícias", "url": "https://www.rtp.pt/noticias/rss", "category": "sports", "lang": "pt" },
|
||||
{ "name": "BBC Sport", "url": "https://feeds.bbci.co.uk/sport/rss.xml", "category": "sports", "lang": "en" },
|
||||
@@ -11,14 +14,18 @@
|
||||
{ "name": "The Guardian World", "url": "https://www.theguardian.com/world/rss", "category": "general", "lang": "en" }
|
||||
],
|
||||
"keywords": [
|
||||
"FC Porto", "Benfica", "Sporting CP", "transfer",
|
||||
"NBA", "F1", "Formula 1", "Cristiano Ronaldo",
|
||||
"Champions League", "Premier League", "La Liga"
|
||||
"andebol", "handball", "EHF", "IHF", "FAP",
|
||||
"Champions League de Andebol", "Liga dos Campeões",
|
||||
"Selecção Nacional", "Seleção Nacional",
|
||||
"FC Porto", "Benfica", "Sporting CP",
|
||||
"andebol de praia", "beach handball", "European Masters",
|
||||
"Mundial", "Campeonato Nacional", "Final Four"
|
||||
],
|
||||
"trusted_domains": [
|
||||
"record.pt", "rtp.pt", "espn.com", "bbc.co.uk",
|
||||
"theguardian.com", "skysports.com", "zerozero.pt",
|
||||
"uefa.com", "fifa.com"
|
||||
"portal.fpa.pt", "record.pt", "rtp.pt",
|
||||
"handball-planet.com", "ihf.info", "eurohandball.com",
|
||||
"bbc.co.uk", "theguardian.com", "espn.com", "skysports.com",
|
||||
"zerozero.pt", "uefa.com", "fifa.com"
|
||||
],
|
||||
"domain_filter_mode": "strict"
|
||||
}
|
||||
Generated
+42
-16
@@ -103,7 +103,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@eslint/eslintrc/node_modules/brace-expansion": {
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.21",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz",
|
||||
"integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -149,7 +151,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array/node_modules/brace-expansion": {
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.21",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz",
|
||||
"integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -426,13 +430,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.18.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.18.0.tgz",
|
||||
"integrity": "sha512-E32NzpYKp++W7XRe52rHiXV2ehxmh3wbdgO7MHeFM+vqxLBYHzt0ElkiImtOBxtOmyp0yoC8C6uESVV84Y2/hw==",
|
||||
"version": "1.20.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.20.0.tgz",
|
||||
"integrity": "sha512-r8aOh8j9cGKpgQAqpzrUHnSIc6a59Y3Xf/cv8sy1DrHCkZHzQGEuoq1tARk6qSyDdtQGSDgpb9kFlruzPvrgwg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.16.0",
|
||||
"form-data": "^4.0.5",
|
||||
"form-data": "^4.0.6",
|
||||
"https-proxy-agent": "^5.0.1",
|
||||
"proxy-from-env": "^2.1.0"
|
||||
}
|
||||
@@ -461,14 +465,16 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "5.0.5",
|
||||
"version": "5.0.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
|
||||
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^4.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18 || 20 || >=22"
|
||||
"node": "20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/braces": {
|
||||
@@ -1007,7 +1013,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/eslint/node_modules/brace-expansion": {
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.21",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz",
|
||||
"integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -1222,7 +1230,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.16.0",
|
||||
"version": "1.16.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.1.tgz",
|
||||
"integrity": "sha512-FNvFGzoMLWmE6Yj9spb/zjd7yiNCHiAW9/Tg9CXrQ8wuu32HtlJOwWO11OJafl5FfY3DxTdQ0vj42zU1kvv5jg==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -1386,7 +1396,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/glob/node_modules/brace-expansion": {
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.21",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz",
|
||||
"integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -1710,8 +1722,20 @@
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.1",
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
|
||||
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
@@ -2593,7 +2617,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/test-exclude/node_modules/brace-expansion": {
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.21",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.21.tgz",
|
||||
"integrity": "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -2679,9 +2705,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "7.28.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz",
|
||||
"integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==",
|
||||
"version": "7.30.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.30.1.tgz",
|
||||
"integrity": "sha512-03KrMbjIFDWQR5RNPrSw3bd1r12JpyFQl9/yxjUbJtqkjmllqC5lFjZh6ujeuJCKr8EOQvRW872Oy/az+nLYxg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20.18.1"
|
||||
|
||||
+11
-2
@@ -39,10 +39,19 @@ function loadSiteConfigs() {
|
||||
|
||||
return fs
|
||||
.readdirSync(sites_dir)
|
||||
.filter((f) => f.endsWith('.json') && f !== 'example.json')
|
||||
.filter((f) => f.endsWith('.json') && !f.endsWith('.example.json') && f !== 'example.json')
|
||||
.map((f) => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path.join(sites_dir, f), 'utf8'));
|
||||
const cfg = JSON.parse(fs.readFileSync(path.join(sites_dir, f), 'utf8'));
|
||||
// Inject credentials from env vars when absent from the site JSON.
|
||||
// Per-site env takes precedence: ANDEBOL_NET_WP_USER / ANDEBOL_NET_WP_PASSWORD.
|
||||
// Falls back to generic WP_USER / WP_PASSWORD for single-site setups.
|
||||
if (!cfg.user || !cfg.password) {
|
||||
const slug = (cfg.name || f.replace('.json', '')).toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
||||
cfg.user = process.env[`${slug}_WP_USER`] || process.env.WP_USER || cfg.user || '';
|
||||
cfg.password = process.env[`${slug}_WP_PASSWORD`] || process.env.WP_PASSWORD || cfg.password || '';
|
||||
}
|
||||
return cfg;
|
||||
} catch (err) {
|
||||
logger.error(`Failed to load site config ${f}: ${err.message}`);
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Fire-and-forget ingest to errors.bitreport.pt (/v1/ingest/events).
|
||||
* Enabled when ERROR_REPORTING_TOKEN is set.
|
||||
*/
|
||||
|
||||
const PROJECT_NAME = 'ai-news-writer';
|
||||
const DEFAULT_PROJECT_SLUG = 'ai-news-writer';
|
||||
const DEFAULT_GITEA_REPO = 'BitReport.pt/ai-news-writer';
|
||||
const INGEST_PATH = '/v1/ingest/events';
|
||||
const MAX_STACK_LEN = 12000;
|
||||
|
||||
function ingestBase() {
|
||||
return (process.env.ERROR_REPORTING_ENDPOINT || 'https://errors.bitreport.pt').replace(/\/$/, '');
|
||||
}
|
||||
|
||||
function ingestToken() {
|
||||
return (process.env.ERROR_REPORTING_TOKEN || '').trim();
|
||||
}
|
||||
|
||||
function routingMeta() {
|
||||
const slug = (process.env.ERROR_REPORTING_PROJECT_SLUG || DEFAULT_PROJECT_SLUG).trim() || DEFAULT_PROJECT_SLUG;
|
||||
const repo = (process.env.ERROR_REPORTING_GITEA_REPO || DEFAULT_GITEA_REPO).trim() || DEFAULT_GITEA_REPO;
|
||||
return { project_slug: slug, gitea_repo: repo };
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an Error (or error-like object) to the hub ingest API. Never throws.
|
||||
* @param {Error} error
|
||||
* @param {{component?: string}} context
|
||||
*/
|
||||
function reportError(error, context = {}) {
|
||||
const token = ingestToken();
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stack = (error && error.stack) || '';
|
||||
const stacktrace = stack.length > MAX_STACK_LEN ? `${stack.slice(0, MAX_STACK_LEN)}\n... (truncated)` : stack;
|
||||
const meta = routingMeta();
|
||||
|
||||
const event = {
|
||||
schema_version: 1,
|
||||
occurred_at: new Date().toISOString(),
|
||||
level: 'error',
|
||||
message: (error && error.message) || String(error),
|
||||
stacktrace,
|
||||
context: {
|
||||
project_name: PROJECT_NAME,
|
||||
project_slug: meta.project_slug,
|
||||
gitea_repo: meta.gitea_repo,
|
||||
component: context.component || 'worker',
|
||||
environment: process.env.NODE_ENV || 'production',
|
||||
error_type: (error && error.name) || 'Error'
|
||||
}
|
||||
};
|
||||
|
||||
const url = `${ingestBase()}${INGEST_PATH}`;
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
'X-Api-Key': token
|
||||
},
|
||||
body: JSON.stringify({ events: [event] })
|
||||
}).catch(() => {
|
||||
// Never let reporting failures affect the app.
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { reportError };
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const { reportError } = require('./errorReporting');
|
||||
|
||||
test('reportError is a no-op without ERROR_REPORTING_TOKEN', async () => {
|
||||
delete process.env.ERROR_REPORTING_TOKEN;
|
||||
const originalFetch = global.fetch;
|
||||
let called = false;
|
||||
global.fetch = async () => {
|
||||
called = true;
|
||||
};
|
||||
try {
|
||||
reportError(new Error('boom'));
|
||||
assert.strictEqual(called, false);
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('reportError posts a well-formed event to /v1/ingest/events when token is set', async () => {
|
||||
process.env.ERROR_REPORTING_TOKEN = 'er_test_token';
|
||||
const originalFetch = global.fetch;
|
||||
let capturedUrl;
|
||||
let capturedBody;
|
||||
global.fetch = async (url, opts) => {
|
||||
capturedUrl = url;
|
||||
capturedBody = JSON.parse(opts.body);
|
||||
return { ok: true };
|
||||
};
|
||||
try {
|
||||
reportError(new Error('boom'), { component: 'worker' });
|
||||
// reportError fires a promise; let the microtask run.
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.ok(capturedUrl.endsWith('/v1/ingest/events'));
|
||||
const event = capturedBody.events[0];
|
||||
assert.strictEqual(event.message, 'boom');
|
||||
assert.strictEqual(event.context.project_slug, 'ai-news-writer');
|
||||
assert.strictEqual(event.context.gitea_repo, 'BitReport.pt/ai-news-writer');
|
||||
assert.strictEqual(event.context.component, 'worker');
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
delete process.env.ERROR_REPORTING_TOKEN;
|
||||
}
|
||||
});
|
||||
@@ -5,6 +5,37 @@ const { scrapeArticle } = require('../crawler/scraper');
|
||||
const { filterByKeywords } = require('../crawler/rss');
|
||||
const logger = require('../logger');
|
||||
|
||||
const TOPIC_ALIASES = {
|
||||
andebol: ['andebol', 'handball'],
|
||||
handball: ['handball', 'andebol']
|
||||
};
|
||||
|
||||
function expandTopicTerms(topic) {
|
||||
const normalized = String(topic || '').trim().toLowerCase();
|
||||
if (!normalized) return [];
|
||||
return TOPIC_ALIASES[normalized] || [normalized];
|
||||
}
|
||||
|
||||
function filterArticlesByTopic(articles, topic, topicLimit) {
|
||||
const terms = expandTopicTerms(topic);
|
||||
let filtered = articles.filter((article) => {
|
||||
const text = `${article.title} ${article.summary}`.toLowerCase();
|
||||
return terms.some((term) => text.includes(term));
|
||||
});
|
||||
|
||||
if (filtered.length === 0) {
|
||||
const category = terms.includes('andebol') ? 'andebol' : topic.toLowerCase();
|
||||
filtered = articles.filter((article) => article.category === category);
|
||||
if (filtered.length > 0) {
|
||||
logger.info(
|
||||
`fetchAndFilterSourceArticles: no text match for topic "${topic}" — using ${filtered.length} feed(s) with category="${category}"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return filtered.slice(0, topicLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch, filter, and optionally enrich articles from RSS/social sources.
|
||||
*
|
||||
@@ -49,13 +80,11 @@ async function fetchAndFilterSourceArticles(sourcesConfig, options = {}) {
|
||||
// Step 2: Apply filtering based on mode
|
||||
let filtered;
|
||||
if (filterMode === 'topic' && topic) {
|
||||
filtered = allArticles.filter((a) =>
|
||||
`${a.title} ${a.summary}`.toLowerCase().includes(topic.toLowerCase())
|
||||
);
|
||||
filtered = filtered.slice(0, topicLimit);
|
||||
filtered = filterArticlesByTopic(allArticles, topic, topicLimit);
|
||||
if (filtered.length === 0) {
|
||||
logger.warn(`fetchAndFilterSourceArticles: no articles match topic "${topic}" — fallback to top ${topicLimit}`);
|
||||
filtered = allArticles.slice(0, topicLimit);
|
||||
logger.warn(
|
||||
`fetchAndFilterSourceArticles: no articles match topic "${topic}" — returning empty set (no general-sports fallback)`
|
||||
);
|
||||
}
|
||||
} else if (filterMode === 'keyword') {
|
||||
filtered = filterByKeywords(allArticles, keywords);
|
||||
|
||||
@@ -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'));
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const logger = require('../logger');
|
||||
const { reportError } = require('../errorReporting');
|
||||
|
||||
let _installed = false;
|
||||
|
||||
@@ -17,13 +18,16 @@ function installProcessDiagnostics() {
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
if (reason instanceof Error) {
|
||||
logger.error(`unhandledRejection: ${reason.message}`, { stack: reason.stack });
|
||||
reportError(reason, { component: 'worker' });
|
||||
return;
|
||||
}
|
||||
logger.error(`unhandledRejection: ${String(reason)}`);
|
||||
reportError(new Error(String(reason)), { component: 'worker' });
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
logger.error(`uncaughtException: ${err.message}`, { stack: err.stack });
|
||||
reportError(err, { component: 'worker' });
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user