撇号 CMS 处理片段和关系的子集

apostrophe CMS dealing with subsets of pieces and relationships

这是我的事件定义

module.exports = {
  extend: 'apostrophe-pieces',
  name: 'event',
  label: 'Event',
  pluralLabel: 'Events',
  addFields: [
    {
      name: 'eventName',
      label: 'Event Name',
      type: 'string',
      required: true
    },
    {
      name: 'location',
      label: 'Location',
      type: 'string',
      required: true
    },
    {
      name: 'date',
      label: 'Date',
      type: 'date',
      required: true
    },
    {
      name: 'thumbnail',
      label: 'Thumbnail',
      type: 'singleton',
      widgetType: 'apostrophe-images',
      options: {
        limit: 1,
        minSize: [ 200, 200 ],
        aspectRatio: [ 1, 1 ]
      }
    }
  ]
};

如何在页面上仅使用 5 个最近的未来事件的子集?

此外,如果我要对客户做类似的事情,我可以根据标识他们行业的字符串字段在不同的页面上使用他们的不同子集吗?

如果您使用 apostrophe-events npm 模块,而不是自己滚动,您所要求的将是 apostrophe-events-widgets 模块的默认行为(显示接下来的 5 个事件' t 结束)。

如果您想自己执行此操作,可以通过将 events 模块的 sort 选项设置为 { date: 1 } 并添加自定义游标过滤器来忽略事件调用时的日期是过去的。然后您将从您的事件小部件模块调用该过滤器方法。

但是,由于 apostrophe-events 为您完成了所有这些工作,并在需要时添加了正确处理开始和结束日期的规定,因此我不推荐 "winging it."

为了完整起见,您可以在此处查看 apostrophe-events 的 "upcoming" 游标过滤器的实现:

https://github.com/apostrophecms/apostrophe-events/blob/master/lib/cursor.js

而且,apostrophe-events-widgets 中的逻辑是使用该过滤器仅显示该小部件中即将发生的事件,您可以将其添加到主页以获得您想要的效果:

https://github.com/apostrophecms/apostrophe-events/blob/master/lib/modules/apostrophe-events-widgets/index.js

apostrophe-events-pages 模块(apostrophe-events 包的一部分)默认情况下也使用此过滤器,但也支持按日期浏览,这会覆盖它以提供对过去事件的访问权限。