Read My Blog With Javascript
mtlynch.io·1d

You can now read my blog with client-side JavaScript. I’m not sure why you’d want to, but you can.

Maybe you want to add a blogroll to your site with a list of recent posts from your favorite blogs, but you don’t want to fetch them server side. If you wanted to use JavaScript to show my five most recent post titles, you’d write some code like this:

fetch("https://mtlynch.io/index.xml")
.then((response) => response.text())
.then((str) => new DOMParser().parseFromString(str, "application/xml"))
.then((data) => {
const articles = [...data.querySelectorAll("item")].map((item) => ({
title: item.querySelector("title").textContent,
date: new Date(item.querySelector("pubDate").textContent),
}));

// Sort articles by date, newest to oldest.
articles.sort((a, b) => b.date - a.date);

// Pr...

Similar Posts

Loading similar posts...