mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
bugfixing and allowing feeds to be generated on request (as opposed to just updated on posting
This commit is contained in:
@@ -36,7 +36,8 @@
|
|||||||
"reds": "~0.2.4",
|
"reds": "~0.2.4",
|
||||||
"winston": "~0.7.2",
|
"winston": "~0.7.2",
|
||||||
"nodebb-plugin-mentions": "~0.1.0",
|
"nodebb-plugin-mentions": "~0.1.0",
|
||||||
"nodebb-plugin-markdown": "~0.1.0"
|
"nodebb-plugin-markdown": "~0.1.0",
|
||||||
|
"rss": "~0.2.0"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/designcreateplay/NodeBB/issues"
|
"url": "https://github.com/designcreateplay/NodeBB/issues"
|
||||||
|
|||||||
28
src/feed.js
28
src/feed.js
@@ -14,13 +14,13 @@
|
|||||||
baseUrl: nconf.get('url') + 'feeds'
|
baseUrl: nconf.get('url') + 'feeds'
|
||||||
};
|
};
|
||||||
|
|
||||||
Feed.saveFeed = function(location, feed) {
|
Feed.saveFeed = function(location, feed, callback) {
|
||||||
var savePath = path.join(__dirname, '../', location);
|
var savePath = path.join(__dirname, '../', location);
|
||||||
|
|
||||||
fs.writeFile(savePath, feed.xml(), function (err) {
|
fs.writeFile(savePath, feed.xml(), function (err) {
|
||||||
if(err) {
|
if(err) return winston.err(err);
|
||||||
winston.err(err);
|
|
||||||
}
|
if (callback) callback(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,24 +41,26 @@
|
|||||||
ttl: Feed.defaults.ttl
|
ttl: Feed.defaults.ttl
|
||||||
}),
|
}),
|
||||||
topic_posts = topicData.main_posts.concat(topicData.posts),
|
topic_posts = topicData.main_posts.concat(topicData.posts),
|
||||||
title, postData;
|
title, postData, dateStamp;
|
||||||
|
|
||||||
for (var i = 0, ii = topic_posts.length; i < ii; i++) {
|
for (var i = 0, ii = topic_posts.length; i < ii; i++) {
|
||||||
title = 'Reply to ' + topicData.topic_name + ' on ' + (new Date(parseInt(topic_posts[i].timestamp, 10)).toUTCString());
|
|
||||||
postData = topic_posts[i];
|
postData = topic_posts[i];
|
||||||
|
dateStamp = new Date(parseInt(postData.edited === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
|
||||||
|
title = 'Reply to ' + topicData.topic_name + ' on ' + dateStamp;
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: title,
|
title: title,
|
||||||
description: postData.content,
|
description: postData.content,
|
||||||
url: nconf.get('url') + 'topic/' + topicData.slug + '#' + postData.pid,
|
url: nconf.get('url') + 'topic/' + topicData.slug + '#' + postData.pid,
|
||||||
author: postData.username,
|
author: postData.username,
|
||||||
date: new Date(parseInt(postData.edited === 0 ? postData.timestamp : postData.edited, 10)).toUTCString()
|
date: dateStamp
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed.saveFeed('feeds/topics/' + tid + '.rss', feed);
|
Feed.saveFeed('feeds/topics/' + tid + '.rss', feed, function(err) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,23 +78,25 @@
|
|||||||
ttl: Feed.defaults.ttl
|
ttl: Feed.defaults.ttl
|
||||||
}),
|
}),
|
||||||
topics = categoryData.topics,
|
topics = categoryData.topics,
|
||||||
title, topicData;
|
title, topicData, dateStamp;
|
||||||
|
|
||||||
for (var i = 0, ii = topics.length; i < ii; i++) {
|
for (var i = 0, ii = topics.length; i < ii; i++) {
|
||||||
title = topics[i].title + '. Posted on ' + (new Date(parseInt(topics[i].timestamp, 10)).toUTCString());
|
|
||||||
topicData = topics[i];
|
topicData = topics[i];
|
||||||
|
dateStamp = new Date(parseInt(topicData.lastposttime, 10)).toUTCString();
|
||||||
|
title = topics[i].title;
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: title,
|
title: title,
|
||||||
url: nconf.get('url') + 'topic/' + topicData.slug,
|
url: nconf.get('url') + 'topic/' + topicData.slug,
|
||||||
author: topicData.username,
|
author: topicData.username,
|
||||||
date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString()
|
date: dateStamp
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed.saveFeed('feeds/categories/' + cid + '.rss', feed);
|
Feed.saveFeed('feeds/categories/' + cid + '.rss', feed, function(err) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}(exports));
|
}(exports));
|
||||||
@@ -210,21 +210,17 @@ var express = require('express'),
|
|||||||
|
|
||||||
|
|
||||||
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
||||||
|
|
||||||
var tid = req.params.topic_id;
|
var tid = req.params.topic_id;
|
||||||
|
|
||||||
if (tid.match(/^\d+\.rss$/)) {
|
if (tid.match(/^\d+\.rss$/)) {
|
||||||
tid = tid.slice(0, -4);
|
tid = tid.slice(0, -4);
|
||||||
var rssPath = path.join(__dirname, '../', 'feeds/topics', tid + '.rss'),
|
var rssPath = path.join(__dirname, '../', 'feeds/topics', tid + '.rss'),
|
||||||
loadFeed = function() {
|
loadFeed = function() {
|
||||||
fs.readFile(rssPath, function (err, data) {
|
fs.readFile(rssPath, function (err, data) {
|
||||||
if (err) {
|
if (err) res.type('text').send(404, "Unable to locate an rss feed at this location.");
|
||||||
res.type('text').send(404, "Unable to locate an rss feed at this location.");
|
else res.type('xml').set('Content-Length', data.length).send(data);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.type('xml').set('Content-Length', data.length).send(data);
|
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fs.existsSync(rssPath)) {
|
if (!fs.existsSync(rssPath)) {
|
||||||
@@ -232,6 +228,8 @@ var express = require('express'),
|
|||||||
loadFeed();
|
loadFeed();
|
||||||
});
|
});
|
||||||
} else loadFeed();
|
} else loadFeed();
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -291,14 +289,22 @@ var express = require('express'),
|
|||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
|
|
||||||
if (cid.match(/^\d+\.rss$/)) {
|
if (cid.match(/^\d+\.rss$/)) {
|
||||||
fs.readFile(path.join(__dirname, '../', 'feeds/categories', cid), function (err, data) {
|
cid = cid.slice(0, -4);
|
||||||
if (err) {
|
var rssPath = path.join(__dirname, '../', 'feeds/categories', cid + '.rss'),
|
||||||
res.type('text').send(404, "Unable to locate an rss feed at this location.");
|
loadFeed = function() {
|
||||||
return;
|
fs.readFile(rssPath, function (err, data) {
|
||||||
}
|
if (err) res.type('text').send(404, "Unable to locate an rss feed at this location.");
|
||||||
|
else res.type('xml').set('Content-Length', data.length).send(data);
|
||||||
res.type('xml').set('Content-Length', data.length).send(data);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!fs.existsSync(rssPath)) {
|
||||||
|
feed.updateCategory(cid, function() {
|
||||||
|
loadFeed();
|
||||||
|
});
|
||||||
|
} else loadFeed();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user