Add short preview to rss news

This commit is contained in:
kpcyrd 2014-09-15 14:53:00 +02:00
parent f448ed429f
commit e1a49398ab

View file

@ -4,25 +4,30 @@ var rss = [
var MAX_RSS = 5; var MAX_RSS = 5;
$(document).ready(function() { $(document).ready(function() {
var addItem = function(title, link, date) { var addItem = function(title, link, date, text) {
var item = $('<a>') var item = $('<a>')
.attr('class', 'css-truncate') .attr('class', 'css-truncate')
.attr('href', link) .attr('href', link)
.attr('target', '_blank') .attr('target', '_blank')
.data('date', date) .data('date', date)
.text(title); .text(title);
$('#news').append($('<li>').append(item)); var prev = $('<p>')
.attr('class', 'css-truncate')
.html(text);
$('#news').append($('<li>').append(item).append(prev));
}; };
var getAddedItems = function() { var getAddedItems = function() {
var news = []; var news = [];
$('#news').find('a').forEach(function(item) { $('#news').find('li').forEach(function(item) {
var a = $(item); var a = $(item).children('a');
var p = $(item).children('p');
var title = a.text(); var title = a.text();
var link = a.attr('href'); var link = a.attr('href');
var date = a.data('date'); var date = a.data('date');
var text = p.html();
news.push({title:title, link:link, date:date}); news.push({title:title, link:link, date:date, text:text});
}); });
return news; return news;
}; };
@ -48,7 +53,7 @@ $(document).ready(function() {
var i = 0; var i = 0;
items.forEach(function(item) { items.forEach(function(item) {
if(i++ >= MAX_RSS) return; if(i++ >= MAX_RSS) return;
addItem(item.title, item.link, item.date); addItem(item.title, item.link, item.date, item.text);
}); });
}; };
@ -60,16 +65,18 @@ $(document).ready(function() {
var title = $(entry).find('title').text(); var title = $(entry).find('title').text();
var link = $(entry).find('link').text(); var link = $(entry).find('link').text();
var date = $(entry).find('pubDate').text(); var date = $(entry).find('pubDate').text();
var text = $(entry).find('description').text();
news.push({title:title, link:link, date:date}); news.push({title:title, link:link, date:date, text:text});
}); });
$(data).find('entry').forEach(function(entry) { $(data).find('entry').forEach(function(entry) {
var title = $(entry).find('title').text(); var title = $(entry).find('title').text();
var link = $(entry).find('link').attr('href'); var link = $(entry).find('link').attr('href');
var date = $(entry).find('published').text(); var date = $(entry).find('published').text();
var text = $(entry).find('content').text();
news.push({title:title, link:link, date:date}); news.push({title:title, link:link, date:date, text:text});
}); });
updateNewsFeed(news); updateNewsFeed(news);