diff --git a/js/main.js b/js/main.js index e3a766d..c8c098e 100644 --- a/js/main.js +++ b/js/main.js @@ -5,34 +5,34 @@ var MAX_RSS = 5; $(document).ready(function() { var i = 0; + + var addItem = function(title, link) { + if(i >= MAX_RSS) return; + + var item = $('') + .attr('class', 'css-truncate') + .attr('href', link) + .attr('target', '_blank') + .text(title); + $('#news').append($('
  • ').append(item)); + + i++; + }; + rss.forEach(function(feed) { $.get('/feeds/' + feed + '.rss', function(data) { $(data).find('item').forEach(function(entry) { - if(i >= MAX_RSS) return; var title = $(entry).find('title').text(); var link = $(entry).find('link').text(); - var item = $('') - .attr('class', 'css-truncate') - .attr('href', link) - .attr('target', '_blank') - .text(title); - $('#news').append($('
  • ').append(item)); - i++; + addItem(title, link); }); $(data).find('entry').forEach(function(entry) { - if(i >= MAX_RSS) return; var title = $(entry).find('title').text(); var link = $(entry).find('link').attr('href'); - var item = $('') - .attr('class', 'css-truncate') - .attr('href', link) - .attr('target', '_blank') - .text(title); - $('#news').append($('
  • ').append(item)); - i++; + addItem(title, link); }); }); });