From 7d04eec30555b8fe838783e7dd9be284fcf35f3a Mon Sep 17 00:00:00 2001 From: Xika Date: Wed, 24 Jun 2026 02:21:00 +0000 Subject: [PATCH 1/3] fix(config): BIT-25761 fix andebol.net WP URL path and example config loading - Exclude *.example.json files from loadSiteConfigs (previously only example.json was excluded, so andebol.net.example.json was loaded as a live config with placeholder credentials) - Correct wp_url from https://andebol.net/wp-json to https://andebol.net (publisher appends /wp-json/wp/v2 itself; the old value caused a doubled path and 404 on every REST call) - Add credential injection in loadSiteConfigs: when user/password are absent from the JSON, merge from ANDEBOL_NET_WP_USER/WP_PASSWORD env vars (or generic WP_USER/WP_PASSWORD fallback) With these fixes wp:test now reaches the correct endpoint and returns 401 instead of 404. Remaining blocker: WP_USER in .env is still a placeholder. Paperclip-Task-Id: BIT-25761 --- config/sites/andebol.net.json | 2 +- src/config/loader.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/sites/andebol.net.json b/config/sites/andebol.net.json index 6b2eed2..9e2d394 100644 --- a/config/sites/andebol.net.json +++ b/config/sites/andebol.net.json @@ -3,7 +3,7 @@ "writing_tone": "formal", "audience_level": "general", "wp_transport": "rest", - "wp_url": "https://andebol.net/wp-json", + "wp_url": "https://andebol.net", "site_domain": "andebol.net", "category_default": 1, "category_infer": "andebol", diff --git a/src/config/loader.js b/src/config/loader.js index e7b54e9..515802e 100644 --- a/src/config/loader.js +++ b/src/config/loader.js @@ -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; -- 2.47.3 From b165de0811e3adbf3e474b00eab66d2b47a643af Mon Sep 17 00:00:00 2001 From: Xika Date: Thu, 25 Jun 2026 14:32:33 +0000 Subject: [PATCH 2/3] feat(sources): add handball RSS feeds for andebol.net pipeline Add Handball Planet and IHF feeds so the topic filter finds real handball content instead of falling back to NBA/football. Also add handball keywords and trusted domains. Fixes off-topic content published to andebol.net (BIT-25828). Co-Authored-By: Paperclip --- config/sources.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config/sources.json b/config/sources.json index 4e09225..a5362db 100644 --- a/config/sources.json +++ b/config/sources.json @@ -1,5 +1,7 @@ { "rss": [ + { "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" }, @@ -13,12 +15,14 @@ "keywords": [ "FC Porto", "Benfica", "Sporting CP", "transfer", "NBA", "F1", "Formula 1", "Cristiano Ronaldo", - "Champions League", "Premier League", "La Liga" + "Champions League", "Premier League", "La Liga", + "handball", "andebol", "EHF", "IHF", "Champions League de Andebol", + "Selecção Nacional", "Porto Handball", "Sporting Handball", "Benfica Handball" ], "trusted_domains": [ "record.pt", "rtp.pt", "espn.com", "bbc.co.uk", "theguardian.com", "skysports.com", "zerozero.pt", - "uefa.com", "fifa.com" + "uefa.com", "fifa.com", "handball-planet.com", "ihf.info" ], "domain_filter_mode": "strict" } -- 2.47.3 From 7262da3e9feeff54447506c73ad2d56fb0bef99d Mon Sep 17 00:00:00 2001 From: Xika Date: Thu, 25 Jun 2026 14:34:44 +0000 Subject: [PATCH 3/3] 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); -- 2.47.3