我正试着用Hugo ssg使用Netlify CMS。
我用:
netlify-cms@1.0
hugo@0.29
我有一个简单的netlify-cms config.yml,有两个集合:帖子和作者。
backend:
name: github
repo: sebhewelt/atlas
branch: master
display_url: https://mypage.com
publish_mode: editorial_workflow
media_folder: "static/uploads"
public_folder: "/uploads"
collections:
- label: "Posts"
name: "post"
folder: "content"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" , format: "YYYY-MM-DD hh:mma"}
- { label: "Body", name: "body", widget: "markdown" }
- label: "Authors"
name: "author"
folder: "data"
create: true
fields:
- {label: "Name", name: "name", widget: "string"}
- {label: "About", name: "about", widget: "string"}
文档区分了两种集合类型,我假设我应该选择文件集合,因为我想将作者数据保存在一个文件中。
我希望能够通过管理信息中心添加作者并将其保存到数据文件夹中的文件中。文档没有提供一个示例,说明如何保存作者的文件(或者cms是否自动生成?)。
我的当前配置遇到错误。当我保存“新作者”时,我得到了这个:
无法持续输入:错误:集合必须具有该字段名称 是有效的条目标识符
为什么我会收到此错误?
答案 0 :(得分:6)
您的作者文件需要位于顶级集合下。此外,如果您希望能够将多个作者添加到文件中,则需要包含" name"和"关于" "列表中的小部件"类型小部件。
示例:
collections:
- label: "Settings"
name: "settings"
files:
- name: "authors"
label: "Authors"
file: "data/authors.yml"
extension: "yml"
fields:
- label: "Author"
name: "author"
widget: "list"
fields:
- {label: "Name", name: "name", widget: "string"}
- {label: "About", name: "about", widget: "string"}
文件集合的CMS文档:https://www.netlifycms.org/docs/collection-types/#file-collections
列表小部件的CMS文档:https://www.netlifycms.org/docs/widgets/#list