mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
added popular rss feed
This commit is contained in:
45
src/feed.js
45
src/feed.js
@@ -159,4 +159,49 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Feed.updatePopular = function(callback) {
|
||||||
|
topics.getTopicsFromSet(0, 'topics:posts', 0, 19, function (err, popularData) {
|
||||||
|
var feed = new rss({
|
||||||
|
title: 'Popular Topics',
|
||||||
|
description: 'A list of topics that are sorted by post count',
|
||||||
|
feed_url: Feed.defaults.baseUrl + '/popular.rss',
|
||||||
|
site_url: nconf.get('url') + '/popular',
|
||||||
|
ttl: Feed.defaults.ttl
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add pubDate if recent topics list contains topics
|
||||||
|
if (popularData.topics.length > 0) {
|
||||||
|
feed.pubDate = new Date(parseInt(popularData.topics[0].lastposttime, 10)).toUTCString();
|
||||||
|
}
|
||||||
|
|
||||||
|
async.eachSeries(popularData.topics, function(topicData, next) {
|
||||||
|
feed.item({
|
||||||
|
title: topicData.title,
|
||||||
|
url: nconf.get('url') + '/topic/' + topicData.slug,
|
||||||
|
author: topicData.username,
|
||||||
|
date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString()
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
}, function() {
|
||||||
|
Feed.saveFeed('feeds/popular.rss', feed, function (err) {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
winston.info('[rss] Re-generated "popular posts" RSS Feed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback) callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Feed.loadFeed = function(rssPath, res) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
}(exports));
|
}(exports));
|
||||||
@@ -832,31 +832,34 @@ module.exports.server = server;
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/recent.rss', function(req, res) {
|
app.get('/recent.rss', function(req, res) {
|
||||||
var rssPath = path.join(__dirname, '../', 'feeds/recent.rss'),
|
var rssPath = path.join(__dirname, '../', 'feeds/recent.rss');
|
||||||
loadFeed = function () {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!fs.existsSync(rssPath)) {
|
if (!fs.existsSync(rssPath)) {
|
||||||
feed.updateRecent(function (err) {
|
feed.updateRecent(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.redirect('/404');
|
res.redirect('/404');
|
||||||
} else {
|
} else {
|
||||||
loadFeed();
|
feed.loadFeed(rssPath, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadFeed();
|
feed.loadFeed(rssPath, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/popular.rss', function(req, res) {
|
||||||
|
var rssPath = path.join(__dirname, '../', 'feeds/popular.rss');
|
||||||
|
|
||||||
|
feed.updatePopular(function (err) {
|
||||||
|
if (err) {
|
||||||
|
res.redirect('/404');
|
||||||
|
} else {
|
||||||
|
feed.loadFeed(rssPath, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/recent/:term?', function (req, res) {
|
app.get('/recent/:term?', function (req, res) {
|
||||||
// TODO consolidate with /recent route as well -> that can be combined into this area. See "Basic Routes" near top.
|
// TODO consolidate with /recent route as well -> that can be combined into this area. See "Basic Routes" near top.
|
||||||
app.build_header({
|
app.build_header({
|
||||||
|
|||||||
Reference in New Issue
Block a user