removed atom-writer (and xml-writer) in favour of node-rss which seems to be better. updated feed.js

v1.18.x
psychobunny 12 years ago
parent f1f86b1d4f
commit 3476be6233

@ -2,7 +2,7 @@
"author": "psychobunny <andrew@designcreateplay.com>, julianlam <julian@designcreateplay.com>, barisusakli <baris@designcreateplay.com>", "author": "psychobunny <andrew@designcreateplay.com>, julianlam <julian@designcreateplay.com>, barisusakli <baris@designcreateplay.com>",
"name": "NodeBB", "name": "NodeBB",
"description": "NodeBB Forum", "description": "NodeBB Forum",
"version": "0.1", "version": "0.0.1",
"homepage": "http://www.nodebb.org", "homepage": "http://www.nodebb.org",
"repository": { "repository": {
"url": "https://github.com/designcreateplay/NodeBB/" "url": "https://github.com/designcreateplay/NodeBB/"
@ -29,8 +29,7 @@
"node-gyp": "0.9.5", "node-gyp": "0.9.5",
"async": "0.2.8", "async": "0.2.8",
"node-imagemagick": "0.1.8", "node-imagemagick": "0.1.8",
"atom-writer": "1.0.3", "node-rss": "1.0.1"
"xml-writer": "1.2.4"
}, },
"devDependencies": {}, "devDependencies": {},
"optionalDependencies": {}, "optionalDependencies": {},

@ -3,43 +3,33 @@
schema = require('./schema.js'), schema = require('./schema.js'),
posts = require('./posts.js'), posts = require('./posts.js'),
topics = require('./topics.js'), topics = require('./topics.js'),
fs = require('fs'); fs = require('fs'),
rss = require('node-rss');
function saveFeed(location, feed, xml) { function saveFeed(location, feed) {
feed.endEntry(); console.log(rss.getFeedXML(feed));
fs.writeFile(location, xml.toString(), function (err) { console.log('derp');
fs.writeFile(location, rss.getFeedXML(feed), function (err) {
if (err) throw err; if (err) throw err;
}); });
} }
function createFeed(xml, urn, title, feed_url, author) { function createFeed(title, description, feed_url, xml_url, author, urn) {
var ATOMWriter = require('atom-writer'), return rss.createNewFeed(
feed = new ATOMWriter(xml); title,
feed_url,
return feed description,
.startFeed(urn) author,
.writeStartIndex(1) xml_url,
.writeItemsPerPage(20) {
.writeTotalResults(20) 'urn' : urn
.writeTitle(title) }
.writeLink(feed_url, 'application/atom+xml', 'self'); );
} }
function createEntry(feed, urn, title, content, url, author) {
return feed
.startEntry(urn)
.writeTitle(title)
.writeLink(url, 'text/html')
.writeContent(content, 'text', 'en')
.writeAuthorRAW(author)
.endEntry();
}
Feed.updateTopic = function(tid, cid) { Feed.updateTopic = function(tid, cid) {
return; var cache_time_in_seconds = 60;
var cache_time_in_seconds = 60, //todo. don't rewrite xml every time something is posted.
XMLWriter = require('xml-writer');
xml = new XMLWriter(true);
function getTopicData(next) { function getTopicData(next) {
topics.getTopicById(tid, 0, function(topicData) { topics.getTopicById(tid, 0, function(topicData) {
@ -58,43 +48,64 @@
var topicData = results[0], var topicData = results[0],
postsData = results[1].postData, postsData = results[1].postData,
userData = results[1].userData, userData = results[1].userData,
url = '/topic/' + topicData.slug; location = '/topic/' + topicData.slug,
xml_url = '/topic/' + tid + '.rss';
var post = topicData.main_posts[0]; var post = topicData.main_posts[0];
var urn = 'urn:' + cid + ':' + tid; var urn = 'urn:' + cid + ':' + tid;
var feed = createFeed(xml, urn, topicData.topic_name, url, post.username);
var feed = createFeed(topicData.topic_name, '', location, xml_url, post.username, urn);
var title; var title;
for (var i = 0, ii = postsData.pid.length; i < ii; i++) { for (var i = 0, ii = postsData.pid.length; i < ii; i++) {
urn = 'urn:' + cid + ':' + tid + ':' + postsData.pid[i]; urn = 'urn:' + cid + ':' + tid + ':' + postsData.pid[i];
title = 'Reply to ' + topicData.topic_name + ' on ' + (new Date(parseInt(postsData.timestamp[i], 10)).toUTCString()); 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);
feed.addNewItem(
title,
location,
postsData.timestamp[i],
postsData.content[i],
{
'urn' : urn,
'username' : userData[postsData.uid[i]].username
}
);
} }
saveFeed('feeds/topics/' + tid + '.rss', feed, xml); saveFeed('feeds/topics/' + tid + '.rss', feed);
}); });
}; };
Feed.updateCategory = function(cid) { Feed.updateCategory = function(cid) {
var XMLWriter = require('xml-writer');
xml = new XMLWriter(true);
categories.getCategoryById(cid, 0, function(categoryData) { categories.getCategoryById(cid, 0, function(categoryData) {
var url = '/category/' + categoryData.category_id + '/' + categoryData.category_name; var location = '/category/' + categoryData.category_id + '/' + categoryData.category_name,
xml_url = '/category' + cid + '.rss';
var urn = 'urn:' + cid; var urn = 'urn:' + cid;
var feed = createFeed(xml, urn, categoryData.category_name, url, 'NodeBB'); // not exactly sure if author for a category should be site_title? var feed = createFeed(categoryData.category_name, '', location, xml_url, 'NodeBB', urn); // not exactly sure if author for a category should be site_title?
var title; var title;
var topics = categoryData.topics; var topics = categoryData.topics;
for (var i = 0, ii = topics.length; i < ii; i++) { for (var i = 0, ii = topics.length; i < ii; i++) {
urn = 'urn:' + cid + ':' + topics[i].tid; urn = 'urn:' + cid + ':' + topics[i].tid;
title = topics[i].title + '. Posted on ' + (new Date(parseInt(topics[i].timestamp, 10)).toUTCString()); title = topics[i].title + '. Posted on ' + (new Date(parseInt(topics[i].timestamp, 10)).toUTCString());
feed = createEntry(feed, urn, title, topics[i].teaser_text, url, topics[i].username);
feed.addNewItem(
title,
location,
topics[i].timestamp,
topics[i].teaser_text,
{
'urn' : urn,
'username' : topics[i].username
}
);
} }
saveFeed('feeds/categories/' + cid + '.rss', feed, xml); saveFeed('feeds/categories/' + cid + '.rss', feed);
}); });
}; };

Loading…
Cancel
Save