首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Netlify CMS在Hugo数据文件中的集合

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

Stack Overflow用户
提问于 2017-12-09 16:21:23
回答 1查看 1.6K关注 0票数 3

我正在努力使我的头脑使用Netlify CMS与雨果ssg。

我用:

代码语言:javascript
复制
netlify-cms@1.0
hugo@0.29

我有一个简单的netlify-cms config.yml,它有两个集合: posts和authors。

代码语言:javascript
复制
  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"}

文档区分了两种集合类型,我假设应该选择文件集合,因为我希望将作者的数据保存在一个文件中。

我希望能够通过管理仪表板添加作者,并将其保存到数据文件夹中。docs没有提供一个示例,说明保存作者的文件应该是什么样子(或者cms是否自动生成它?)。

我在当前配置中遇到了一个错误。当我拯救“新作者”时,我得到了这样的信息:

未能持久化条目:错误:集合必须有一个有效的输入标识符的字段名

为什么我会有这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-09 16:45:37

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

示例:

代码语言:javascript
复制
  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

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47730571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档