Skip to content

Instantly share code, notes, and snippets.

@rxhanson
Last active March 14, 2020 14:48
Show Gist options
  • Save rxhanson/92b0bce9455fff1eaaaddc1c65eff086 to your computer and use it in GitHub Desktop.
Save rxhanson/92b0bce9455fff1eaaaddc1c65eff086 to your computer and use it in GitHub Desktop.
Parse your sparkle appcast into html, so you don't have to manually add it into your versions page
$(document).ready(function(){
$.ajax({
type: "GET" ,
url: "downloads/updates.xml" ,
dataType: "xml" ,
success: function(xml) {
var items = []
$(xml).find('item').each(function(){
var item = $(this)
var description = item.find('description').text()
// only include ones that have a description
if (description === "") {
return
}
var parsedItem = {}
parsedItem.title = item.find('title').text()
parsedItem.date = new Date(item.find('pubDate').text())
parsedItem.url = item.find('enclosure').attr('url')
parsedItem.description = description
items.push(parsedItem)
});
// sort by most recent first
items.sort(function(a, b){
return a.date > b.date ? -1 : 1;
})
// cut it to first 3
items = items.slice(0, 3)
items.forEach(function(item, index) {
var div = $('<div></div>')
var title = index === 0 ? item.title + ' Current Version': item.title
div.append('<h4><a href="' + item.url + '">' + title + ' <i class="fas fa-download"></i></a></h4>')
div.append(item.description)
$("#versions").append(div)
})
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment