diff --git a/.gitignore b/.gitignore index 241a5d3a28..9809b6d72c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules/ tmp/ *.log .idea/ -coverage/ \ No newline at end of file +coverage/ +yarn.lock diff --git a/lib/plugins/generator/post.js b/lib/plugins/generator/post.js index 581cfa2626..8ac4ddddee 100644 --- a/lib/plugins/generator/post.js +++ b/lib/plugins/generator/post.js @@ -1,7 +1,7 @@ 'use strict'; function postGenerator(locals) { - var posts = locals.posts.sort('-date').toArray(); + var posts = locals.posts.sort('date').toArray(); var length = posts.length; return posts.map(function(post, i) { diff --git a/test/scripts/generators/post.js b/test/scripts/generators/post.js index 06278cfd69..de1b376f8c 100644 --- a/test/scripts/generators/post.js +++ b/test/scripts/generators/post.js @@ -76,14 +76,19 @@ describe('post', function() { {source: 'baz', slug: 'baz', date: 1e8 - 1} ]).then(function(posts) { return generator(locals()).then(function(data) { - should.not.exist(data[0].data.prev); - data[0].data.next._id.should.eql(posts[0]._id); - data[1].data.prev._id.should.eql(posts[1]._id); - data[1].data.next._id.should.eql(posts[2]._id); + // Posts should be sorted by date + data[0].data._id.should.eql(posts[2]._id); + data[1].data._id.should.eql(posts[0]._id); + data[2].data._id.should.eql(posts[1]._id); - data[2].data.prev._id.should.eql(posts[0]._id); + data[0].data.next._id.should.eq(posts[0]._id); + data[1].data.next._id.should.eq(posts[1]._id); should.not.exist(data[2].data.next); + + should.not.exist(data[0].data.prev); + data[1].data.prev._id.should.eq(posts[2]._id); + data[2].data.prev._id.should.eq(posts[0]._id); }).thenReturn(posts); }).map(function(post) { return post.remove();