laktek / punch-blog

A boilerplate to create personal blogs based on Punch
MIT License
45 stars 14 forks source link

Recent posts show in ascending order #9

Closed ghost closed 11 years ago

ghost commented 11 years ago

When rendering the recent posts list on the index page, the oldest posts show at the top, descending towards more recent posts. This appears to be incorrect, since one would expect a "Recent Posts" list to show posts in descending order, from newest to oldest.

If this is a genuine bug, and not intended behavior, it can be fixed by modifying line 20 of helpers/index_helper.js so that it reads:

var allposts = .values(posts_obj);

instead of:

var allposts = .values(posts_obj).reverse();

laktek commented 11 years ago

Hmm..it should be newest posts shown at the top. That's why there's an explicit reverse. What's the post URL structure you're using?

ghost commented 11 years ago

I used the default post URL structure.

With the default post URL structure, and the stock index_helper.js, my posts show in the same order as the output of ls -al in the posts directory:

-rw-rw-r--. 1 matthew matthew 2778 Feb 2 22:06 2009-07-30-I-should-have-thought-of-this.markdown -rw-rw-r--. 1 matthew matthew 1102 Feb 2 22:06 2009-07-31-The-Sisters-of-Mercy-When-You-Dont-See-Me.markdown -rw-rw-r--. 1 matthew matthew 3521 Feb 2 22:06 2009-08-27-real-life-isnt-like-that.markdown -rw-rw-r--. 1 matthew matthew 2509 Feb 2 22:07 2009-09-20-I-found-some-treats.markdown -rw-rw-r--. 1 matthew matthew 1960 Feb 2 22:09 2009-09-22-afraid-to-shoot-strangers-scene-5.markdown -rw-rw-r--. 1 matthew matthew 2137 Feb 2 22:07 2009-10-15-renaissance-2009.markdown -rw-rw-r--. 1 matthew matthew 1412 Feb 2 22:07 2012-09-03-How-The-Phoenix-Society-Really-Works.markdown -rw-rw-r--. 1 matthew matthew 1617 Feb 2 22:08 2012-09-04-The-Hardest-Part-is-Yet-to-Come.markdown -rw-rw-r--. 1 matthew matthew 1181 Feb 2 22:08 2012-09-05-Krystal-Wade-Wildes-Meadow-cover-reveal.markdown

In addition, only the first post in this list shows up.

ghost commented 11 years ago

By the way, I'm running node v0.9.5 on Fedora 18, if that's relevant.

thisgeek commented 11 years ago

I can confirm this issue.

You have the posts in the correct order right up until you pass the basepath to getPost() on line 27. Instead of calling recent_posts_list.shift() to get the first post on the list, you call recent_posts_list.pop(), which gets the last. This causes each value of post_contents to be pushed onto recent_posts in reverse on line 41.

laktek commented 11 years ago

Merged the pull request from @thisgeek.