Reputation: 1612
working on my docpad blog, in testing I see sorting is descending by the title, but most blogs are sorted ascending.
How would you suggest solving this?
Upvotes: 1
Views: 716
Reputation: 4938
There are several ways to do this. In fact you can order it by name, extension, date etc.
Since you want to have it sorted by date you need to add a date
meta entry to your file:
---
title: Post name
layout: post
date: 2013-09-26
---
Post content blah blah blah.
The focus is on the date
entry, it's format is YEAR-MONTH-DAY
.
Then you can have the following:
@getCollection('html').findAllLive({relativeOutDirPath:'posts'},[{date:-1}])
The important part being [{date:-1}]
. That would put the latest posts first, if you want it the other way around make it just a one without the -
: [{date:1}]
Hope that helps!
Oh BTW, that example I provided is from a more complex query: https://github.com/Greduan/eduantech.docpad/blob/d5e97638331ab24730d3331b9fbcc30cf1d46dcc/docpad.coffee#L45-L49
Upvotes: 0
Reputation: 1612
In docpad.coffee I added
posts: -> @getCollection('documents').findAllLive({relativeOutDirPath:'blog'},[timestamp:-1])
and then I add a timestamp to all the markdown files.
Upvotes: 2