-
Notifications
You must be signed in to change notification settings - Fork 35
/
rss.js
35 lines (28 loc) · 961 Bytes
/
rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var fs = require('fs');
var makeBlogRss = function (posts) {
var genTime = (new Date()).toUTCString();
var buf = '<?xml version="1.0"?>' +
'<rss version="2.0">' +
'<channel>' +
'<title>@briantford\'s blog</title>' +
'<link>http://briantford.com/blog/</link>' +
'<description>@briantford\'s blog | mostly AngularJS tutorials</description>' +
'<language>en-us</language>' +
'<pubDate>' + genTime + '</pubDate>' +
'<lastBuildDate>' + genTime + '</lastBuildDate>';
posts.forEach(function (post) {
buf += makePostRss(post);
});
buf += '</channel>' +
'</rss>';
return buf;
};
var makePostRss = function (post) {
return '<item>' +
'<title>' + post.title + '</title>' +
'<link>' + post.link + '</link>' +
'<pubDate>' + post.date + '</pubDate>' +
'</item>';
};
var posts = JSON.parse(fs.readFileSync('json/blog.json'));
fs.writeFileSync('out/blog.rss', makeBlogRss(posts));