Skip to content

Commit

Permalink
rss support
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzhang-cn committed Mar 17, 2012
1 parent f04b6e7 commit 5eca619
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
13 changes: 12 additions & 1 deletion config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ exports.config = {
// 话题列表显示的话题数量
list_topic_count: 20,

// RSS
rss: {
title: 'CNode:Node.js专业中文社区',
link: 'http://cnodejs.org',
language: 'zh-cn',
description: 'CNode:Node.js专业中文社区',

//最多获取的RSS Item数量
max_rss_items: 50
},

// mail SMTP
mail_port: 25,
mail_user: 'club',
Expand All @@ -48,4 +59,4 @@ exports.config = {
var host = exports.config.host;
if (host[host.length - 1] === '/') {
exports.config.host = host.substring(0, host.length - 1);
}
}
37 changes: 37 additions & 0 deletions controllers/rss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var topic_ctrl = require('./topic');

var config = require('../config').config;
var data2xml = require('data2xml');

exports.index = function (req,res,next) {
var opt = { limit: config.rss.max_rss_items, sort: [['create_at','desc']] };

topic_ctrl.get_topics_by_query({}, opt, function (err, topics) {
if(err) return next(err);

var rss_obj = {
_attr: { version: '2.0' },
channel: {
title: config.rss.title,
link: config.rss.link,
language: config.rss.language,
description: config.rss.description
},
item: []
};

topics.forEach(function (topic) {
rss_obj.item.push({
title: topic.title,
content: topic.content,
//author: topic.author,
link: config.rss.link + '/topic/' + topic._id
});
});

var rss_content = data2xml('rss', rss_obj);

res.contentType('application/xml');
res.send(rss_content);
});
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"node-markdown": "0.1.0",
"validator": "0.3.7",
"ndir": "0.1.2",
"nodemailer": "0.3.5"
"nodemailer": "0.3.5",
"data2xml": "0.4.0"
}
}
6 changes: 5 additions & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var message = require('./controllers/message');
var tag = require('./controllers/tag');
var topic = require('./controllers/topic');
var reply = require('./controllers/reply');
var rss = require('./controllers/rss');
var upload = require('./controllers/upload');
var static = require('./controllers/static');
var tools =require('./controllers/tools');
Expand Down Expand Up @@ -93,4 +94,7 @@ exports = module.exports = function(app) {
// static
app.get('/about', static.about);
app.get('/faq', static.faq);
};

//rss
app.get('/rss', rss.index);
};

0 comments on commit 5eca619

Please sign in to comment.