Javascript Atom feed reader
Jul. 31st, 2025 10:48 pmHere's the Javascript code I use to echo an HTML version of my atom feed to my updates page.
HTML in
To register the feed on the HTML page as well, add this in
HTML in
<content> must be used as < and > instead of as brackets (<>).<ul id="feed-list">
<script>
fetch('../feed.xml') // relative link to feed
.then(response => response.text())
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
.then(data => {
const entries = data.querySelectorAll('entry'); // each update is in an <entry>
const feedList = document.getElementById('feed-list'); // id of unordered list (see first line)
entries.forEach(entry => {
const li = document.createElement('li');
const title = entry.querySelector('title')?.textContent || '';
const content = entry.querySelector('content[type="html"]')?.textContent || '';
li.innerHTML = `<b>{title}</b><div></div>`;
if (content) {
li.querySelector('div').innerHTML = content;
}
feedList.appendChild(li);
});
})
.catch(err => {
document.getElementById('feed-list').innerHTML = '<li>Error loading feed.</li>';
});
</script>
</ul>To register the feed on the HTML page as well, add this in
<head>:<link rel="alternate" type="application/rss+xml" title="name of feed" href="complete link to feed" />
no subject
Date: 2025-08-01 12:13 pm (UTC)