Skip to content
This repository
Browse code

whoops. make the feed sort proper like

  • Loading branch information...
commit 73d0432075295060b4c38b6053a1d9265b90f55e 1 parent 65f291a
Brian LeRoux authored

Showing 2 changed files with 7 additions and 8 deletions. Show diff stats Hide diff stats

  1. +3 8 lib/post.js
  2. +4 0 test/run.js
11 lib/post.js
@@ -3,7 +3,8 @@ var fs = require('fs')
3 3 , path = require('path')
4 4 , md2html = require('showdown').md2html
5 5 , prettyfy = require('highlight').Highlight
6   -, postsPath = path.join(__dirname, '../posts');
  6 +, postsPath = path.join(__dirname, '../posts')
  7 +, sorter = function(a,b) { return b.substr(0,10).replace(/-/g,'') - a.substr(0,10).replace(/-/g,'') }
7 8
8 9
9 10 var Post = function (filename) { this.filename = filename }
@@ -15,12 +16,6 @@ Post.all = function (files) {
15 16 }
16 17
17 18 Post.page = function (page) {
18   - var sorter = function(a,b) {
19   - var a = a.substr(0,10).replace(/-/g,'')
20   - , b = b.substr(0,10).replace(/-/g,'')
21   - return b-a
22   - }
23   -
24 19 var self = this
25 20 , files = fs.readdirSync(postsPath).sort(sorter)
26 21 , posts = Post.all(files)
@@ -52,7 +47,7 @@ Post.rss = function () {
52 47 s += '<title>' + title + '</title>';
53 48 s += '<generator>http://github.com/brianleroux/node-code-blog</generator>';
54 49 s += '<link>http://' + domain + '/</link>';
55   - var posts = Post.all(fs.readdirSync(postsPath).reverse());
  50 + var posts = Post.all(fs.readdirSync(postsPath).sort(sorter));
56 51 for (var i = 0; i < 5; i++) {
57 52 s += '<item>';
58 53 s += '<title>' + posts[i].title() + '</title>';
4 test/run.js
@@ -6,6 +6,10 @@ var testrunner = require('nodeunit').testrunner
6 6 exports['tests post'] = function(test){
7 7 test.ok(Post, 'post exists')
8 8 test.equals(Post.page(1).posts.length, 5, '5 post per page')
  9 +
  10 + var page1 = Post.page(1).posts
  11 +
  12 +
9 13 test.done()
10 14 }
11 15

0 comments on commit 73d0432

Please sign in to comment.
Something went wrong with that request. Please try again.