Skip to content

Instantly share code, notes, and snippets.

@rjack
Created April 21, 2011 15:40
Show Gist options
  • Save rjack/934796 to your computer and use it in GitHub Desktop.
Save rjack/934796 to your computer and use it in GitHub Desktop.
Node RSS output
// This module should listen for http requests to a given URL and output an RSS feed.
var connect = require("connect");
connect.createServer(
connect.logger(),
connect.router(routes)
).listen(8080);
function routes (app) {
app.get("/feed/:id", function (req, res, next) {
res.writeHead(200, {
"content-type": "text/xml"
});
res.write('<?xml version="1.0" encoding="utf-8"?>\n');
res.write('<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">\n');
res.write('<channel>\n');
res.write(' <title>' + req.params.id + '</title>\n');
res.write(' <link>http://www.' + req.params.id + '.com</link>\n');
res.write(' <lastBuildDate>Sun, 17 Apr 2011 15:00:24 +0000</lastBuildDate>\n');
res.write(' <language>en</language>\n');
res.write(' <sy:updatePeriod>hourly</sy:updatePeriod>\n');
res.write(' <sy:updateFrequency>1</sy:updateFrequency>\n');
res.write(' <item>\n');
res.write(' <title>SEE#6 conference</title>\n');
res.write(' <link>http://www.' + req.params.id+ '.com/2011/04/12/see6-conference/</link>\n');
res.write(' <pubDate>Tue, 12 Apr 2011 06:27:01 +0000</pubDate>\n');
res.write(' <dc:creator>May Cuntent</dc:creator>\n');
res.write(' <guid isPermaLink="false">http://www.' + req.params.id + '.com/?p=661</guid>\n');
res.write(' </item>\n');
res.write('</channel>\n');
res.end();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment