Skip to content

Instantly share code, notes, and snippets.

@simon-brooke
Created July 16, 2023 10:48
Show Gist options
  • Save simon-brooke/2e9ca045afb082030f2e262254ec1ae0 to your computer and use it in GitHub Desktop.
Save simon-brooke/2e9ca045afb082030f2e262254ec1ae0 to your computer and use it in GitHub Desktop.
Embed an RSS feed into a web page using only locally sourced JQuery
<script src="/blog/js/jquery-3.7.0.min.js" type="application/javascript"></script>
<div class="social-media">
<hr/>
<h4>Recent Mastodon posts</h4>
<ol id="mastodon"></ol>
<script type="text/javascript">
const RSS_URL = "https://mastodon.scot/@simon_brooke.rss";
function getRSSFeed(feed, target) {
$.ajax(feed, {
accepts: {
xml: "application/rss+xml"
},
dataType: "xml",
success: function (data) {
$(data).find("item").each(
function (i, element) {
const el = $(this);
$(target).append('<li>' +
el.find("description").text() +
'<a href="' +
el.find("link").text() + '">' +
"[" + el.find("pubDate").text() + "]</a></li>"
);
return i < 5;
}
);
}
});
}
getRSSFeed(RSS_URL, "#mastodon");
</script>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment