Custom Text

You can call me Arrow or aroceu, whatever your heart desires. I write stories and code, I make graphics and designs, I talk about myself a lot, and I prefer lists in threes but break that preference quite often.
ceu: (hilda)
[personal profile] ceu
Here's the Javascript code I use to echo an HTML version of my atom feed to my updates page.

HTML in <content> must be used as &lt; and &gt; 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" />
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting