Merge pull request 'fix(sources): BIT-25828 andebol RSS feeds and topic filter' (#27) from fix/BIT-25828-andebol-rss-feeds into main
ai-news-writer-ci / test (push) Failing after 7s
ai-news-writer-ci / test (push) Failing after 7s
This commit was merged in pull request #27.
This commit is contained in:
commit
4ed62556ee
4 files changed
+60
-15
No files matched your search
@@ -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",
|
||||
|
||||
+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"
|
||||
}
|
||||
+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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user