Merge pull request #5 from The-R4V3N/feat/clickable-ticker-articles
Add clickable article links to Live News Ticker
This commit is contained in:
@@ -89,6 +89,16 @@ function geoTagText(text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function sanitizeExternalUrl(raw) {
|
||||
if (!raw) return undefined;
|
||||
try {
|
||||
const url = new URL(raw);
|
||||
return url.protocol === 'http:' || url.protocol === 'https:' ? url.toString() : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// === RSS Fetching ===
|
||||
async function fetchRSS(url, source) {
|
||||
try {
|
||||
@@ -100,8 +110,9 @@ async function fetchRSS(url, source) {
|
||||
while ((match = itemRegex.exec(xml)) !== null) {
|
||||
const block = match[1];
|
||||
const title = (block.match(/<title>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/title>/)?.[1] || '').trim();
|
||||
const link = sanitizeExternalUrl((block.match(/<link>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/link>/)?.[1] || '').trim());
|
||||
const pubDate = block.match(/<pubDate>(.*?)<\/pubDate>/)?.[1] || '';
|
||||
if (title && title !== source) items.push({ title, date: pubDate, source });
|
||||
if (title && title !== source) items.push({ title, date: pubDate, source, url: link || undefined });
|
||||
}
|
||||
return items;
|
||||
} catch (e) {
|
||||
@@ -142,6 +153,7 @@ export async function fetchAllNews() {
|
||||
title: item.title.substring(0, 100),
|
||||
source: item.source,
|
||||
date: item.date,
|
||||
url: item.url,
|
||||
lat: geo.lat + (Math.random() - 0.5) * 2,
|
||||
lon: geo.lon + (Math.random() - 0.5) * 2,
|
||||
region: geo.region
|
||||
@@ -460,17 +472,17 @@ function buildNewsFeed(rssNews, gdeltData, tgUrgent, tgTop) {
|
||||
for (const n of rssNews) {
|
||||
feed.push({
|
||||
headline: n.title, source: n.source, type: 'rss',
|
||||
timestamp: n.date, region: n.region, urgent: false
|
||||
timestamp: n.date, region: n.region, urgent: false, url: n.url
|
||||
});
|
||||
}
|
||||
|
||||
// GDELT top articles
|
||||
for (const title of (gdeltData.allArticles || []).slice(0, 10).map(a => a.title)) {
|
||||
if (title) {
|
||||
const geo = geoTagText(title);
|
||||
for (const a of (gdeltData.allArticles || []).slice(0, 10)) {
|
||||
if (a.title) {
|
||||
const geo = geoTagText(a.title);
|
||||
feed.push({
|
||||
headline: title.substring(0, 100), source: 'GDELT', type: 'gdelt',
|
||||
timestamp: new Date().toISOString(), region: geo?.region || 'Global', urgent: false
|
||||
headline: a.title.substring(0, 100), source: 'GDELT', type: 'gdelt',
|
||||
timestamp: new Date().toISOString(), region: geo?.region || 'Global', urgent: false, url: sanitizeExternalUrl(a.url)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user