2

我对 Netlify 的 CMS 有点困惑——特别是在通过config.yml. 我正在使用带有 Gatsby 静态站点的 Netlify CMS,以允许最终用户更新网站上的一些动态数据。

我想要达到的目标:

我希望 CMS 上的数据类型允许用户创建新的旅行日期,最大入住人数和当前入住人数(即当前有多少人在所述旅行中预订)。

为了实现这一点,我目前已经这样做了config.yml(这config.yml位于static/admin我的 Gatsby 项目 wrt 项目根目录中):

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为单个文件,然后在其中填充大量的游览实例。

有人能指出我如何在不死的情况下实现这组旅游数据点的正确方向吗?

4

1 回答 1

5

您可以将该集合设为文件夹集合或使用列表小部件

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

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. 但是,对于大量数据来说,它看起来真的很不规则,您可能想要使用自定义宽度对其进行分页,或者使用文件夹集合。

于 2019-04-05T03:16:46.410 回答