Skip to content

Instantly share code, notes, and snippets.

@Synvox
Created October 27, 2016 17:27
Show Gist options
  • Save Synvox/ba2145aa9d73ba7349404084599e1e51 to your computer and use it in GitHub Desktop.
Save Synvox/ba2145aa9d73ba7349404084599e1e51 to your computer and use it in GitHub Desktop.
RSS Activities Reader Example
const getEvents = (url='http://calendar.byui.edu/RSSFeeds.aspx?data=tq9cbc8b%2btuQeZGvCTEMSP%2bfv3SYIrjQ3VTAXA335bE0WtJCqYU4mp9MMtuSlz6MRZ4LbMUU%2fO4%3d')=>{
return new Promise((resolve, reject)=>{
fetch(url)
.then(res=>res.text()).then(function(xml) {
const doc = new DOMParser().parseFromString(xml, 'text/xml')
const activities = []
Array.prototype.slice.call(doc.getElementsByTagName('item')).forEach((item)=>{
activities.push({
title: item.querySelector('title').textContent,
description: item.querySelector('description').textContent,
date: new Date(Date.parse(item.querySelector('pubDate').textContent)),
href: item.querySelector('link').textContent
})
})
resolve(activities.sort((a,b)=>a.date - b.date))
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment