From 7262da3e9feeff54447506c73ad2d56fb0bef99d Mon Sep 17 00:00:00 2001 From: Xika Date: Thu, 25 Jun 2026 14:34:44 +0000 Subject: [PATCH] fix(sources): complete BIT-25828 andebol RSS feeds and topic filter Add FAP feed, handball-only keywords, and remove general-sports fallback when topic=andebol so NBA/football articles are not published to andebol.net. --- config/sources.json | 19 ++++++++------- src/pipeline/source-articles.js | 41 ++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/config/sources.json b/config/sources.json index a5362db..09cb977 100644 --- a/config/sources.json +++ b/config/sources.json @@ -1,5 +1,6 @@ { "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" }, @@ -13,16 +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", - "handball", "andebol", "EHF", "IHF", "Champions League de Andebol", - "Selecção Nacional", "Porto Handball", "Sporting Handball", "Benfica Handball" + "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", "handball-planet.com", "ihf.info" + "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" } diff --git a/src/pipeline/source-articles.js b/src/pipeline/source-articles.js index 4e2d260..c4b20a7 100644 --- a/src/pipeline/source-articles.js +++ b/src/pipeline/source-articles.js @@ -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);