Created
October 27, 2016 17:27
-
-
Save Synvox/ba2145aa9d73ba7349404084599e1e51 to your computer and use it in GitHub Desktop.
RSS Activities Reader Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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