Browse files

whoops. make the feed sort proper like

  • Loading branch information...
1 parent 65f291a commit 73d0432075295060b4c38b6053a1d9265b90f55e @brianleroux committed Mar 9, 2011
Showing with 7 additions and 8 deletions.
  1. +3 −8 lib/post.js
  2. +4 −0 test/run.js
View
11 lib/post.js
@@ -3,7 +3,8 @@ var fs = require('fs')
, path = require('path')
, md2html = require('showdown').md2html
, prettyfy = require('highlight').Highlight
-, postsPath = path.join(__dirname, '../posts');
+, postsPath = path.join(__dirname, '../posts')
+, sorter = function(a,b) { return b.substr(0,10).replace(/-/g,'') - a.substr(0,10).replace(/-/g,'') }
var Post = function (filename) { this.filename = filename }
@@ -15,12 +16,6 @@ Post.all = function (files) {
}
Post.page = function (page) {
- var sorter = function(a,b) {
- var a = a.substr(0,10).replace(/-/g,'')
- , b = b.substr(0,10).replace(/-/g,'')
- return b-a
- }
-
var self = this
, files = fs.readdirSync(postsPath).sort(sorter)
, posts = Post.all(files)
@@ -52,7 +47,7 @@ Post.rss = function () {
s += '<title>' + title + '</title>';
s += '<generator>http://github.com/brianleroux/node-code-blog</generator>';
s += '<link>http://' + domain + '/</link>';
- var posts = Post.all(fs.readdirSync(postsPath).reverse());
+ var posts = Post.all(fs.readdirSync(postsPath).sort(sorter));
for (var i = 0; i < 5; i++) {
s += '<item>';
s += '<title>' + posts[i].title() + '</title>';
View
4 test/run.js
@@ -6,6 +6,10 @@ var testrunner = require('nodeunit').testrunner
exports['tests post'] = function(test){
test.ok(Post, 'post exists')
test.equals(Post.page(1).posts.length, 5, '5 post per page')
+
+ var page1 = Post.page(1).posts
+
+
test.done()
}

0 comments on commit 73d0432

Please sign in to comment.