// feed.js // Use the Atom feed URL const ATOM_FEED_URL = "https://cors-anywhere.herokuapp.com/https://leonick.se/feeds/rsi/atom"; async function loadAtomFeed() { try { const response = await fetch(ATOM_FEED_URL); // If CORS is blocked, you'll need to use a proxy or a server-side solution. const feedText = await response.text(); // Parse the Atom feed (XML) using DOMParser const parser = new DOMParser(); const xmlDoc = parser.parseFromString(feedText, "application/xml"); // Select all elements (Atom entries) const entries = xmlDoc.querySelectorAll("entry"); const feedContainer = document.getElementById("feed-container"); feedContainer.innerHTML = ""; // Clear the loading message entries.forEach((entry, index) => { // Optionally, limit the number of entries displayed (e.g., first 5) if (index >= 5) return; const title = entry.querySelector("title")?.textContent || "No Title"; // Atom feed links are typically in a tag with rel="alternate" const linkEl = entry.querySelector("link[rel='alternate']") || entry.querySelector("link"); const link = linkEl ? linkEl.getAttribute("href") : "#"; const updated = entry.querySelector("updated")?.textContent || ""; // Use if available, otherwise use const summary = entry.querySelector("summary")?.textContent || entry.querySelector("content")?.textContent || ""; const article = document.createElement("article"); article.innerHTML = `

${title}

Updated: ${updated}

${summary.substring(0, 300)}...

`; feedContainer.appendChild(article); }); } catch (error) { console.error("Error loading the Atom feed:", error); document.getElementById("feed-container").textContent = "Could not load the feed. See console for details."; } } document.addEventListener("DOMContentLoaded", loadAtomFeed);