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

@@ -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 {}
}