Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

blog: Generate RSS feeds

  • Loading branch information...
commit d34fea59e1b72d5da60ca97f3decb84f5ed87ef1 1 parent 5565366
@isaacs isaacs authored
Showing with 60 additions and 5 deletions.
  1. +1 −1  Makefile
  2. +45 −0 doc/rss.xml
  3. +14 −4 tools/blog/generate.js
View
2  Makefile
@@ -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 $@
View
45 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>
View
18 tools/blog/generate.js
@@ -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
@@ -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() {
@@ -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));
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.