我对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
定义为单个文件,然后用大量的游览实例填充它。
有人能指出我如何在没有文件死亡的情况下实现这一系列的旅游数据点的正确方向吗?
您可以将该集合设为folder collection或使用list widget。
使用list的示例,包含您的代码:
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对其进行分页,或使用文件夹集合。