Changes to the compse yml and the way and amout of artikeltexte are delivered and taht not duplicates are displayed

This commit is contained in:
hubble_dubble
2026-01-26 00:59:03 +00:00
parent 08a1f54a40
commit 71ff9344a1
4 changed files with 89 additions and 13 deletions

View File

@@ -38,10 +38,16 @@ async function loadNews() {
const lines = text.split("\n").map((line) => line.trim()).filter(Boolean);
const items = [];
const seen = new Set();
for (const line of lines) {
try {
const parsed = JSON.parse(line);
const fallbackTitle = stripTags(parsed.title);
const id = parsed.id || parsed.link || fallbackTitle || `idx:${items.length}`;
if (seen.has(id)) continue;
seen.add(id);
items.push({
id,
title: stripTags(parsed.title),
text: stripTags(parsed.text),
link: parsed.link,
@@ -49,7 +55,7 @@ async function loadNews() {
} catch (err) {
console.warn("NDJSON parse error", err);
}
if (items.length >= 60) break;
if (items.length >= 20) break;
}
newsContainer.innerHTML = "";

View File

@@ -32,9 +32,14 @@ async function ladeNews() {
const loadingEl = null;
container.innerHTML = "";
const newsIndex = new Map();
const maxItems = 20;
let renderedCount = 0;
const getKey = (nachricht) => {
if (nachricht?.id) return `id:${nachricht.id}`;
if (nachricht?.link) return `link:${nachricht.link}`;
if (nachricht?.title) return `title:${stripTags(nachricht.title)}`;
if (nachricht?.publishedAt) return `ts:${nachricht.publishedAt}`;
@@ -109,13 +114,15 @@ async function ladeNews() {
const existing = newsIndex.get(key);
if (existing) {
updateFields(existing, nachricht);
return;
return false;
}
const state = buildItem(nachricht);
updateFields(state, nachricht);
newsIndex.set(key, state);
container.appendChild(state.item);
renderedCount += 1;
return true;
};
try {
@@ -136,6 +143,7 @@ async function ladeNews() {
const decoder = new TextDecoder("utf-8");
let buffer = "";
let stop = false;
while (true) {
const { value, done } = await reader.read();
if (done) break;
@@ -148,19 +156,27 @@ async function ladeNews() {
const s = line.trim();
if (!s) continue;
try {
renderItem(JSON.parse(s));
foundAny = true;
const added = renderItem(JSON.parse(s));
if (added) foundAny = true;
if (renderedCount >= maxItems) {
stop = true;
break;
}
} catch (e) {
console.warn("NDJSON parse error:", s.slice(0, 200));
}
}
if (stop) break;
}
if (stop) {
await reader.cancel();
}
const last = buffer.trim();
if (last) {
if (last && renderedCount < maxItems) {
try {
renderItem(JSON.parse(last));
foundAny = true;
const added = renderItem(JSON.parse(last));
if (added) foundAny = true;
} catch {}
}