Created
December 20, 2012 22:58
-
-
Save jsantangelo/4349360 to your computer and use it in GitHub Desktop.
Javascript to aggregate Atom feeds, using Google's Feed API.
This file contains 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
google.load("feeds", "1"); | |
function AtomEntry(date, text, repo) { | |
this.date = date; | |
this.text = text; | |
this.repo = repo; | |
} | |
function compareDate(a, b) { | |
if (a.date < b.date) | |
return 1; | |
if (a.date > b.date) | |
return -1; | |
return 0; | |
} | |
function loadFeeds(feedlist) { | |
var entries = []; | |
var numFeeds = feedlist.length; | |
for (var i = 0; i < feedlist.length; i++) { | |
var feed = new google.feeds.Feed(feedlist[i]); | |
feed.setNumEntries(10); | |
feed.load(function(result) { | |
if (!result.error) { | |
for (var j = 0; j < result.feed.entries.length; j++) { | |
var rawEntry = result.feed.entries[j]; | |
var formattedDate = new Date(rawEntry.publishedDate); | |
var repopattern = /\s[^ ]+(?=:)/g; | |
entries.push(new AtomEntry(formattedDate, rawEntry.title, repopattern.exec(result.feed.title))); | |
} | |
numFeeds--; | |
if (numFeeds == 0) { | |
entries.sort(compareDate); | |
var container = document.getElementById("feedcontent"); | |
for (var k = 0; k < entries.length; k++) { | |
var datediv = document.createElement("div"); | |
datediv.className = "feeddate"; | |
datediv.appendChild(document.createTextNode(entries[k].date.toLocaleDateString())); | |
container.appendChild(datediv); | |
var textdiv = document.createElement("div"); | |
var span = document.createElement("span"); | |
span.className = "feedrepo"; | |
var reponame = document.createTextNode(entries[k].repo); | |
span.appendChild(reponame); | |
textdiv.appendChild(span); | |
var committext = document.createTextNode(" : " + entries[k].text); | |
textdiv.appendChild(committext); | |
container.appendChild(textdiv); | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment