按发布日期过滤Keystone帖子

时间:2018-08-30 13:54:48

标签: keystonejs

我希望KeystoneJS博客仅显示发布日期等于或大于今天的帖子。我猜那是在那儿的过滤器设置中发生的:

view.on('init', function (next) {

    var q = keystone.list('Post').paginate({
        page: req.query.page || 1,
        perPage: 9,
        maxPages: 10,
        filters: {
            state: 'published',
        },
    })
        .sort('-publishedDate')
        .populate('author categories')
...

必须有一种在某处设置publishedDate <= Date.now的方法,但我看不到...

更新

找到了:

var today = new Date();

view.on('init', function (next) {

    var q = keystone.list('Post').paginate({
        page: req.query.page || 1,
        perPage: 3,
        maxPages: 3,
        filters: {
            state: 'published',
            publishedDate: {
                $lte: today,
            },
        },
    })
    ...

0 个答案:

没有答案