Netlify CMS - 如何通过 config.yml 集合存储对象数组

Netlify CMS - how to store an array of objects via config.yml collections

我对 Netlify 的 CMS 有点困惑 - 特别是在通过 config.yml 定义模式时。我将 Netlify CMS 与 Gatsby 静态站点一起使用,以允许最终用户更新网站上的一些动态数据。

我想要达到的目标:

我想要 CMS 上的一种数据类型,以允许用户创建新的旅游日期、最大入住人数和当前入住人数(即当前预订该旅游的人数)。

为了实现这一点,我目前使用了这个 config.yml(这个 config.yml 位于我的 Gatsby 项目的 static/admin w.r.t 项目根目录中):

backend:
  name: git-gateway
  branch: master

publish_mode: editorial_workflow

media_folder: src/images/uploads
public_folder: /uploads

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - {label: "Tour Date", name: "date", widget: "datetime"}
          - {label: "Total Places", name: "totalPlaces", widget: "number"}
          - {label: "Filled Places", name: "filledPlaces", widget: "number"}

虽然这似乎不是我要找的东西,但我似乎无法创建多个巡演日期实例,只能创建一个。也许这是我对集合类型的根本误解,但我认为我可以将 tour 定义为单个文件,然后用大量的 tour 实例填充它。

有人能给我指明正确的方向,说明如何通过文件实现这一系列旅游数据点而不致死亡吗?

您可以将该合集设为 folder collection or use a list widget

使用列表的示例,以及您的代码:

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - label: "Tour List"
            name: "tourList"
            widget: "list"
            fields:
              - {label: "Tour Date", name: "date", widget: "datetime"}
              - {label: "Total Places", name: "totalPlaces", widget: "number"}
              - {label: "Filled Places", name: "filledPlaces", widget: "number"}

因此您的旅行日期、地点等可以放在列表的 fields 下。但是,对于大量数据来说,它看起来真的很不守规矩,您可能想使用自定义 widet 对其进行分页,或使用文件夹集合。