Browse Source

blog: Generate RSS feeds

v0.8.7-release
isaacs 13 years ago
parent
commit
d34fea59e1
  1. 2
      Makefile
  2. 45
      doc/rss.xml
  3. 18
      tools/blog/generate.js

2
Makefile

@ -136,7 +136,7 @@ blogclean:
rm -rf out/blog rm -rf out/blog
blog: doc/blog out/Release/node tools/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): $(apidoc_dirs):
mkdir -p $@ mkdir -p $@

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>

18
tools/blog/generate.js

@ -10,6 +10,7 @@ var semver = require('semver');
var input = path.resolve(process.argv[2]); var input = path.resolve(process.argv[2]);
var output = path.resolve(process.argv[3]); var output = path.resolve(process.argv[3]);
var template = path.resolve(process.argv[4]); var template = path.resolve(process.argv[4]);
var rssTemplate = path.resolve(process.argv[5]);
var config = { var config = {
postsPerPage: 4 postsPerPage: 4
@ -20,7 +21,13 @@ console.error("argv=%j", process.argv)
fs.readFile(template, 'utf8', function(er, contents) { fs.readFile(template, 'utf8', function(er, contents) {
if (er) throw er; if (er) throw er;
template = ejs.compile(contents, template); 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() { function readInput() {
@ -101,14 +108,15 @@ function buildPermalink(key, post) {
return data; return data;
} }
function writeFile(uri, data) { function writeFile(uri, data, templ) {
if (!templ) templ = template;
data.uri = path.join(data.uri); data.uri = path.join(data.uri);
uri = path.join(uri); uri = path.join(uri);
var contents = template(data); var contents = templ(data);
var outdir = path.join(output, uri); var outdir = path.join(output, uri);
mkdirp(outdir, function(er) { mkdirp(outdir, function(er) {
if (er) throw 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) { fs.writeFile(file, contents, 'utf8', function(er) {
if (er) throw er; if (er) throw er;
console.log('wrote: ', data.pageid, path.relative(process.cwd(), file)); console.log('wrote: ', data.pageid, path.relative(process.cwd(), file));
@ -248,8 +256,10 @@ function writePaginated(title, posts, p, total, id) {
}; };
if (p === 0) { if (p === 0) {
writeFile(uri, d); writeFile(uri, d);
writeFile('/feed' + uri, d, rssTemplate);
} }
writeFile(uri + p, d); writeFile(uri + p, d);
writeFile('/feed' + uri + p, d, rssTemplate);
} }
function buildOutput(data) { function buildOutput(data) {

Loading…
Cancel
Save