wrapped up rss for topics. added a new route to access these feeds from the url topic/tid.rss

v1.18.x
psychobunny 12 years ago
parent 9a15177d50
commit 4b17f1d4e6

@ -2,11 +2,15 @@
var RDB = require('./redis.js'),
schema = require('./schema.js'),
posts = require('./posts.js'),
topics = require('./topics.js');
topics = require('./topics.js'),
fs = require('fs');
function saveFeed(feed, xml) {
function saveFeed(feed, xml, tid) {
feed.endEntry();
console.log(xml.toString())
fs.writeFile('feeds/topics/' + tid + '.rss', xml.toString(), function (err) {
if (err) throw err;
});
}
function createFeed(xml, urn, title, feed_url, author) {
@ -25,7 +29,7 @@
function createEntry(feed, urn, title, content, url, author) {
return feed
.startEntry(urn)
.writeTitle('Reply #' + title)
.writeTitle(title)
.writeLink(url, 'text/html')
.writeContent(content, 'text', 'en')
.writeAuthorRAW(author)
@ -54,18 +58,20 @@
var topicData = results[0],
postsData = results[1].postData,
userData = results[1].userData,
url = topicData.category_slug + '/' + topicData.slug;
url = '/topic/' + topicData.slug;
var post = topicData.main_posts[0];
var urn = 'urn:' + cid + ':' + tid;
var feed = createFeed(xml, urn, topicData.topic_name, url, post.username);
var title;
for (var i = 0, ii = postsData.pid.length; i < ii; i++) {
urn = 'urn:' + cid + ':' + tid + ':' + postsData.pid[i];
feed = createEntry(feed, urn, postsData.pid[i], postsData.content[i], url, userData[postsData.uid[i]].username);
title = 'Reply to ' + topicData.topic_name + ' on ' + (new Date(parseInt(postsData.timestamp[i], 10)).toUTCString());
feed = createEntry(feed, urn, title, postsData.content[i], url, userData[postsData.uid[i]].username);
}
saveFeed(feed, xml);
saveFeed(feed, xml, tid);
});
};

@ -94,8 +94,21 @@ var express = require('express'),
// Complex Routes
app.get('/topic/:topic_id/:slug?', function(req, res) {
var topic_url = req.params.topic_id + (req.params.slug ? '/' + req.params.slug : '');
topics.get_cid_by_tid(req.params.topic_id, function(cid) {
var tid = req.params.topic_id;
if (tid.match('.rss')) {
fs.readFile('feeds/topics/' + tid, function (err, data) {
if (err) {
res.send("Unable to locate an rss feed at this location.");
return;
}
res.send(data);
});
return;
}
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
topics.get_cid_by_tid(tid, function(cid) {
res.send(
build_header() +
'<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' +

Loading…
Cancel
Save