1/*! (c) Lynx Information Systems Ltd 2023 */ 2 3jQuery(document).ready(function($) { 4 5 const mastodonRssUrl = "https://mastodon.world/@ukogl.rss"; 6 const maxItems = 3; // number of most recent items to show 7 8 fetch(mastodonRssUrl) 9 .then(response => response.text()) 10 .then(text => new DOMParser().parseFromString(text, "text/xml")) 11 .then(xml => showPosts(xml)); 12 13 function showPosts(xml) { 14 // show the 5 latest posts 15 const xmlItems = xml.querySelectorAll("item:nth-of-type(-n+"+maxItems+")"); 16 17 var domItems = []; // NodeList returned by querySelectorAll does not support map(), but does allow forEach 18 xmlItems.forEach(item => { 19 20 // pubDate format is DAY, DD Mon YYYY HH:MM:SS Z, strip out DD Mon YYYY 21 var pubdate = item.querySelector("pubDate").innerHTML.split(" ").filter((s,i) => i>0 && i<4).join(" "); 22 var postLink = $("<a>").addClass("pubdate").attr("href", item.querySelector("link").innerHTML).html(pubdate); 23 24 // item description is encoded HTML 25 var html = new DOMParser().parseFromString(item.querySelector("description").innerHTML, "text/html"); 26 var description = $("<div>").addClass("description").html(html.documentElement.textContent); 27 28 var media = item.querySelectorAll("media\\:content, content"); // with or without namespace 29 var images = []; // NodeList returned by querySelectorAll does not support map(), but does allow forEach 30 media.forEach(content => { 31 // wrap each img in a div.media 32 var result = $("<div>").addClass("media"); 33 result.append($("<img>").attr("src", content.getAttribute("url"))) 34 images.push(result); 35 }); 36 37 domItems.push( 38 $("<div>").addClass("mastodonItem") 39 .append($("<div>").addClass("itemTitle").append(postLink)) 40 .append($("<div>").addClass("itemContent").append(description).append(images)) 41 ); 42 }); 43 44 $("#mastodonItems").append(domItems); 45 } // showPosts 46});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.