I have a Keystone.js blog and I want to add blog archives similar to Wordpress /archive/year/month. I added some extra date fields to the post object but I feel there is a way to do this using the published date.
Right now archive year is just '2014' and archive month is '06', while the '-publishedDate' value would be something like "publishedDate" : Date( 1355644800000 )
. Is there a way to write a function in the query to parse the date as a JS date object then match the values?
// Load the posts
view.on('init', function(next) {
var q = keystone.list('Post').paginate({
page: req.query.page || 1,
perPage: 10,
maxPages: 10
})
.where('state', 'published')
.sort('-publishedDate')
.populate('author categories');
if (locals.data.category) {
q.where('categories').in([locals.data.category]);
}
// If archive section, filter by year and month
if (locals.data.archiveYear && locals.data.archiveMonth) {
q.where('-publishedDate',locals.data.archiveYear);
q.where('-publishedDate',locals.data.archiveMonth);
}
q.exec(function(err, results) {
locals.data.posts = results;
next(err);
});
});