Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
blog: Generate RSS feeds
  • Loading branch information
isaacs committed Jun 22, 2012
1 parent 5565366 commit d34fea5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -136,7 +136,7 @@ blogclean:
rm -rf out/blog

blog: doc/blog out/Release/node tools/blog
out/Release/node tools/blog/generate.js doc/blog/ out/blog/ doc/blog.html
out/Release/node tools/blog/generate.js doc/blog/ out/blog/ doc/blog.html doc/rss.xml

$(apidoc_dirs):
mkdir -p $@
Expand Down
45 changes: 45 additions & 0 deletions doc/rss.xml
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
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/"
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
<title>Node.js Blog</title>
<atom:link href="http://blog.nodejs.org<%= uri %>" rel="self" type="application/rss+xml" />
<link>http://blog.nodejs.org/</link>
<description>The Blog about Node.js</description>
<lastBuildDate><%= new Date().toUTCString() %></lastBuildDate>
<language>en</language>
<sy:updatePeriod>weekly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>http://nodejs.org/</generator>
<image>
<url>http://nodejs.org/images/logo-light.png</url>
<title>Node.js</title>
<link>http://blog.nodejs.org/</link>
</image>
<%
posts.forEach(function(post) {
%>
<item>
<title><%= post.title %></title>
<link>http://blog.nodejs.org<%= post.permalink %></link>
<pubDate><%= post.date.toUTCString() %></pubDate>
<dc:creator><%= post.author %></dc:creator>
<category><![CDATA[<%= post.category %>]]></category>
<guid isPermaLink="true">http://blog.nodejs.org<%= post.permalink %></guid>
<description><![CDATA[<%- post.content %>]]></description>
<content:encoded><![CDATA[<%- post.content %>]]></content:encoded>
</item>
<%
});
%>
</channel>
</rss>
18 changes: 14 additions & 4 deletions tools/blog/generate.js
Expand Up @@ -10,6 +10,7 @@ var semver = require('semver');
var input = path.resolve(process.argv[2]);
var output = path.resolve(process.argv[3]);
var template = path.resolve(process.argv[4]);
var rssTemplate = path.resolve(process.argv[5]);

var config = {
postsPerPage: 4
Expand All @@ -20,7 +21,13 @@ console.error("argv=%j", process.argv)
fs.readFile(template, 'utf8', function(er, contents) {
if (er) throw er;
template = ejs.compile(contents, template);
readInput();
template.filename = 'index.html';
fs.readFile(rssTemplate, 'utf8', function(er, contents) {
if (er) throw er;
rssTemplate = ejs.compile(contents, rssTemplate);
rssTemplate.filename = 'index.xml';
readInput();
});
});

function readInput() {
Expand Down Expand Up @@ -101,14 +108,15 @@ function buildPermalink(key, post) {
return data;
}

function writeFile(uri, data) {
function writeFile(uri, data, templ) {
if (!templ) templ = template;
data.uri = path.join(data.uri);
uri = path.join(uri);
var contents = template(data);
var contents = templ(data);
var outdir = path.join(output, uri);
mkdirp(outdir, function(er) {
if (er) throw er;
var file = path.resolve(outdir, 'index.html');
var file = path.resolve(outdir, templ.filename);
fs.writeFile(file, contents, 'utf8', function(er) {
if (er) throw er;
console.log('wrote: ', data.pageid, path.relative(process.cwd(), file));
Expand Down Expand Up @@ -248,8 +256,10 @@ function writePaginated(title, posts, p, total, id) {
};
if (p === 0) {
writeFile(uri, d);
writeFile('/feed' + uri, d, rssTemplate);
}
writeFile(uri + p, d);
writeFile('/feed' + uri + p, d, rssTemplate);
}

function buildOutput(data) {
Expand Down

0 comments on commit d34fea5

Please sign in to comment.