Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Javascript Rss Reader

#Javascript Rss Reader#

Takes a rss feed and prints html (defined by a template) for every post.

<!DOCTYPE html>
<div id=blog></div>
//function to make "XMLHttpRequest" object chainable
for(a in b=z.prototype)(function(c,d){b[a]=function(){d=c.apply(this,arguments);return d===undefined?this:d}})(b[a]);
function printRss(file,template){
//the string that will be returned
txt = "",
//get all "entry" elements from a rss feed
x = (new XMLHttpRequest)
//a templating function that outputs the content of the rss xml tags when it encounters double curly braces {{}}
//example: "{{content}}" will output the content of the "<content>" xml tag of the rss feed
tmpl = function(){
return template.replace(/\{\{([^{}]+)}}/g,function(b,c){
return x[i].getElementsByTagName(c)[0].firstChild.nodeValue
txt += tmpl();
return txt
document.getElementById("blog").innerHTML = printRss(
//the file:
//the template to use:
<article> \
<h3> \
<time>{{updated}}</time> \
</h3> \
{{content}} \
</article> \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment