Permalink
Browse files

generate blog index and rss from json

  • Loading branch information...
btford committed Sep 17, 2012
1 parent 9fd5dbb commit f3bc78f4bd8228c04b0184235e8929ef8a181bdd
Showing with 60 additions and 20 deletions.
  1. +4 −1 Makefile
  2. +7 −2 compile.js
  3. +11 −15 jade/blog/index.jade
  4. +2 −1 jade/templates/main.jade
  5. +1 −1 json/blog.json
  6. +35 −0 rss.js
View
@@ -30,13 +30,16 @@ STATIC_OUT_DIR = $(OUT_DIR)
JS_CONCAT_FILES = $(shell find $(JS_IN_DIR)/*.js)
.PHONY: all
-all: html css js images
+all: html css js images rss
all-compress: css-compress html-compress js-compress images
html:
node compile.js
+rss:
+ node rss.js
+
misc:
rsync -vaz $(RSYNC_EXCLUDES) $(STATIC_IN_DIR)/ $(STATIC_OUT_DIR)
View
@@ -2,7 +2,8 @@
var fs = require('fs'),
jade = require('jade'),
- _ = require('underscore');
+ _ = require('underscore'),
+ moment = require('moment');
jade.filters.javascript = function (str) {
return '<pre class="prettyprint linenums lang-js">' + str.replace(/\\/g, '\\\\').replace(/\n/g, '\\n') + '</pre>';
@@ -49,11 +50,15 @@ var compile = function (dir) {
var locals;
try {
- locals = {json: JSON.parse(fs.readFileSync('json/' + page + '.json')) };
+ locals = JSON.parse(fs.readFileSync(jadeBase + dir + '/' + page + '.json'));
} catch (e) {} //idc lol
if (!locals) {
locals = {};
}
+ locals.posts = JSON.parse(fs.readFileSync('json/blog.json'));
+ locals.posts.forEach(function (post) {
+ post.date = moment(post.date).format('YYYY.MM.DD');
+ });
//locals.title = filename.substr(0, -5);
View
@@ -3,19 +3,15 @@ extends ../templates/main
block main
h2 Blog
section
- for item in json
+ for item in posts
p
- .date [#{item.date}]
- :markdown
- <span class="date">[2012.09.10]</span> [Using Yeoman with AngularJS](angular-yeoman.html)
-
- <span class="date">[2012.07.31]</span> [Using the D3.js Visualization Library with AngularJS](angular-d3.html)
-
- <span class="date">[2012.07.17]</span> [Writing an AngularJS App with Socket.io](angular-socket-io.html) | Featured on [HTML5 Rocks](http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/)
-
- <span class="date">[2012.07.14]</span> [Stop Whining About New JS Frameworks](too-many-frameworks-qq.html)
-
- <span class="date">[2012.07.02]</span> [Introducing the AngularJS Batarang](http://blog.angularjs.org/2012/07/introducing-angularjs-batarang.html)
-
- <span class="date">[2012.06.20]</span> [Writing an AngularJS App with an Express + Node.js Backend](angular-express.html) | Featured in [Appliness Issue #4](http://appliness.com/code/Appliness-July-pdf.pdf)
-2
+ span.date [#{item.date}]
+ a(href='#{item.link}') #{item.title}
+ if item.feat
+ | | Featured
+ if item.feat.on
+ | on
+ a(href='#{item.feat.link}') #{item.feat.on}
+ if item.feat.in
+ | in
+ a(href='#{item.feat.link}') #{item.feat.in}
View
@@ -15,8 +15,9 @@ html.no-js(lang='en')
Modernizr enables HTML5 elements & feature detects;
Respond is a polyfill for min/max-width CSS3 Media Queries
//-
- <script src="/js/libs/modernizr-1.7.min.js"></script>
+ <script src="/js/libs/modernizr-1.7.min.js"></script>
script(src='/js/libs/respond.min.js')
+ link(rel="alternate", type="application/rss+xml", title="RSS", href="/blog.rss")
body
#container.container_12
header.grid_10
View
@@ -6,7 +6,7 @@
}, {
"title": "Using the D3.js Visualization Library with AngularJS",
"date": "Tue, July 31 2012 13:13:37 -0700",
- "link": "http://briantford.com/blog/angular-d3.html",
+ "link": "http://briantford.com/blog/angular-d3.html"
}, {
"title": "Writing an AngularJS App with Socket.io",
"date": "Tue, Jul 17 2012 16:49:56 -0700",
View
35 rss.js
@@ -0,0 +1,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));

3 comments on commit f3bc78f

@zugaldia

This comment has been minimized.

Show comment Hide comment
@zugaldia

zugaldia Sep 21, 2012

Liking this.

Liking this.

@btford

This comment has been minimized.

Show comment Hide comment
@btford

btford Sep 21, 2012

Owner

Haha, the RSS feed is live here if you're interested: http://briantford.com/blog.rss :)

Owner

btford replied Sep 21, 2012

Haha, the RSS feed is live here if you're interested: http://briantford.com/blog.rss :)

@zugaldia

This comment has been minimized.

Show comment Hide comment
@zugaldia

zugaldia Sep 21, 2012

No complains from Google Reader.

No complains from Google Reader.

Please sign in to comment.