Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created September 15, 2012 17:04
Show Gist options
  • Save davybrion/3728853 to your computer and use it in GitHub Desktop.
Save davybrion/3728853 to your computer and use it in GitHub Desktop.
code snippets for "Displaying Feed Items On A Web Page: My Solution" post
var express = require('express'),
app = module.exports = express.createServer(),
NodePie = require('nodepie'),
request = require('request'),
recentFeedItems = null;
app.dynamicHelpers({
getRecentFeedItems: function() {
return recentFeedItems;
}
});
// ... some extra configuration of Express that isn't relevant to this post
var processFeed = function(callback) {
request('http://feeds.feedburner.com/davybrion', function(err, response, body) {
if (!err && response.statusCode == 200) {
var feed = new NodePie(body);
feed.init();
recentFeedItems = feed.getItems(0, 5);
if (callback) callback();
};
});
};
setInterval(processFeed, 1800000); // process feed items every 30 minutes
processFeed(function() {
app.listen(3000);
console.log('Express started on port 3000');
});
<ul>
<% getRecentFeedItems.forEach(function(item) { %>
<li><time class="date"><%= item.getDate().getDate() + '/' + (item.getDate().getMonth() + 1) %></time><a href="<%= item.getPermalink() %>"><%= item.getTitle() %></a></li>
<% }); %>
</ul>
app.dynamicHelpers({
getRecentFeedItems: function() {
return recentFeedItems;
}
});
var processFeed = function(callback) {
request('http://feeds.feedburner.com/davybrion', function(err, response, body) {
if (!err && response.statusCode == 200) {
var feed = new NodePie(body);
feed.init();
recentFeedItems = feed.getItems(0, 5);
if (callback) callback();
};
});
};
setInterval(processFeed, 1800000); // process feed items every 30 minutes
processFeed(function() {
app.listen(3000);
console.log('Express started on port 3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment