使用 Netlify CMS 在 Hugo 数据文件中的集合

Collections in Hugo data file using Netlify CMS

我正在尝试将 Netlify CMS 与 Hugo ssg 结合使用。

我使用:

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 会自动生成它吗?)。

我的当前配置遇到错误。当我保存 "New Author" 我得到这个:

Failed to persist entry: Error: Collection must have a field name that is a valid entry identifier

为什么会出现此错误?

您的作者文件需要位于顶级合集中。此外,如果您希望能够将多个作者添加到文件中,则需要将 "name" 和 "about" 小部件包装在 "list" 类型的小部件中。

示例:

  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