I am building an aggregator that takes news stories from XML and outputs them as individual LI's.
I need to cast the data for the date (currently outputs as Mon, 16 Dec 2013 11:00:00 GMT
) into a numerical format so that I can then run queries on the date.
For example I need to:
- Select the 10 most recent items from the array
- Store these in a sub-array
- Randomise the sub-array and output
Essentially so the last 10 news stories are taken and then randomised.
The code so far is working here (takes 5 seconds to load) and is generated by:
<script>
jQuery(function(){
$.ajax({
url: 'http://www.sagittarius-digital.com/news.rss',
dataType: 'xml'
}).done(function(xml){
var items = $(xml).find('item').map(function(){
var $item = $(this);
var array = '<li class="ourNewsItem">';
array += '<a href="' + $item.find('link').text() + '">';
array += '<h2>' + $item.find('title').text() + '</h2>';
array += '<p>' + $item.find('description').text() + '</p>';
array += '<p>' + $item.find('pubDate').text() + '</p>';
array += '<p>Category: ' + $item.find('category').text() + '</p>';
array += '</a>';
array += '</li>';
return array;
}).get();
$('ul').append(items.join(' '));
}).fail(function(){
console.log('error', arguments)
})
})
</script>