【问题标题】:netlify cms gatsby getting "must have identifier_field set" for collectionnetlify cms gatsby 获取“必须设置标识符字段”以进行收集
【发布时间】:2019-05-12 22:51:54
【问题描述】:

您好,我在gatsby-starter-netlify-cms 工作,并设置了一个名为“Bios”的辅助博客,我将该博客用作模板并从 .md 文件中正确显示,问题是当我尝试更新添加内容管理器正确显示的新简历,但是当我按下发布时,它从未真正发布更改(绿线永远消失......)

控制台显示:“未捕获(承诺中)错误:集合必须具有一个有效条目标识符的字段名称,或者必须设置 identifier_field”

回购位于https://github.com/theMakersOrg/theMakersWebsiteV2

这是我的 config.yaml 中的代码

backend:
  name: git-gateway
  branch: master

media_folder: static/img
public_folder: /img

collections:
  - name: 'blog'
    label: 'Blog'
    folder: 'src/pages/blog'
    create: true
    slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
    fields:
      - {
          label: 'Template Key',
          name: 'templateKey',
          widget: 'hidden',
          default: 'blog-post',
        }
      - { label: 'Title', name: 'title', widget: 'string' }
      - { label: 'Publish Date', name: 'date', widget: 'datetime' }
      - { label: 'Description', name: 'description', widget: 'text' }
      - { label: 'Body', name: 'body', widget: 'markdown' }
      - { label: 'Tags', name: 'tags', widget: 'list' }

  - name: 'bios'
    label: 'Bio'
    folder: 'src/pages/bios'
    create: true
    slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
    fields:
      - {
          label: 'Template Key',
          name: 'templateKey',
          widget: 'hidden',
          default: 'bio-post',
        }
      - { label: 'Name', name: 'name', widget: 'string' }
      - { label: 'Publish Date', name: 'publishDate', widget: 'datetime' }
      - { label: 'Description', name: 'description', widget: 'text' }
      - { label: 'image', name: 'image1', widget: 'image' }
      - { label: 'Body', name: 'body', widget: 'markdown' }
      - { label: 'Tags', name: 'tags', widget: 'list' }

  - name: 'pages'
    label: 'Pages'
    files:
      - file: 'src/pages/about/index.md'
        label: 'About'
        name: 'about'
        fields:
          - {
              label: 'Template Key',
              name: 'templateKey',
              widget: 'hidden',
              default: 'about-page',
            }
          - { label: 'Title', name: 'title', widget: 'string' }
          - { label: 'Body', name: 'body', widget: 'markdown' }
      - file: 'src/pages/products/index.md'
        label: 'Products Page'
        name: 'products'
        fields:
          - {
              label: 'Template Key',
              name: 'templateKey',
              widget: 'hidden',
              default: 'product-page',
            }
          - { label: Title, name: title, widget: string }
          - { label: Image, name: image, widget: image }
          - { label: Heading, name: heading, widget: string }
          - { label: Description, name: description, widget: string }
          - {
              label: Intro,
              name: intro,
              widget: object,
              fields:
                [
                  { label: Heading, name: heading, widget: string },
                  { label: Description, name: description, widget: text },
                  {
                    label: Blurbs,
                    name: blurbs,
                    widget: list,
                    fields:
                      [
                        { label: Image, name: image, widget: image },
                        { label: Text, name: text, widget: text },
                      ],
                  },
                ],
            }
          - {
              label: Main,
              name: main,
              widget: object,
              fields:
                [
                  { label: Heading, name: heading, widget: string },
                  { label: Description, name: description, widget: text },
                  {
                    label: Image1,
                    name: image1,
                    widget: object,
                    fields:
                      [
                        { label: Image, name: image, widget: image },
                        { label: Alt, name: alt, widget: string },
                      ],
                  },
                  {
                    label: Image2,
                    name: image2,
                    widget: object,
                    fields:
                      [
                        { label: Image, name: image, widget: image },
                        { label: Alt, name: alt, widget: string },
                      ],
                  },
                  {
                    label: Image3,
                    name: image3,
                    widget: object,
                    fields:
                      [
                        { label: Image, name: image, widget: image },
                        { label: Alt, name: alt, widget: string },
                      ],
                  },
                ],
            }
          - {
              label: Testimonials,
              name: testimonials,
              widget: list,
              fields:
                [
                  { label: Quote, name: quote, widget: string },
                  { label: Author, name: author, widget: string },
                ],
            }
          - { label: Full_image, name: full_image, widget: image }
          - {
              label: Pricing,
              name: pricing,
              widget: object,
              fields:
                [
                  { label: Heading, name: heading, widget: string },
                  { label: Description, name: description, widget: string },
                  {
                    label: Plans,
                    name: plans,
                    widget: list,
                    fields:
                      [
                        { label: Plan, name: plan, widget: string },
                        { label: Price, name: price, widget: string },
                        {
                          label: Description,
                          name: description,
                          widget: string,
                        },
                        { label: Items, name: items, widget: list },
                      ],
                  },
                ],
            }

【问题讨论】:

  • 检查页面时浏览器的控制台是否有错误?
  • 有一个看起来很可疑。 “未捕获(承诺中)错误:集合必须有一个作为有效条目标识符的字段名称,或者必须设置 identifier_field
  • 设法通过添加标识符字段来修复它

标签: gatsby netlify netlify-cms


【解决方案1】:

注意:文件夹集合必须至少有一个名称为 title 的字段,用于创建新的条目 slug。该字段应使用默认字符串小部件。该字段的标签可以是任何字符串值。如果您希望使用不同的字段作为标识符,请将 identifier_field 设置为字段名称。

需要根据docs设置identifier_field

- name: 'bios'
label: 'Bio'
folder: 'src/pages/bios'
create: true
slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
format: 'frontmatter'
identifier_field: makerName
fields:
  - {
      label: 'Template Key',
      name: 'templateKey',
      widget: 'hidden',
      default: 'bio-post',
    }
  - { label: 'Maker Name', name: 'makerName', widget: 'string' }
  - { label: 'Publish Date', name: 'publishDate', widget: 'datetime' }
  - { label: 'Description', name: 'description', widget: 'text' }
  - { label: 'image', name: 'image1', widget: 'image' }
  - { label: 'Body', name: 'body', widget: 'markdown' }
  - { label: 'Tags', name: 'tags', widget: 'list' }

【讨论】:

猜你喜欢
  • 2023-03-22
  • 1970-01-01
  • 2019-02-23
  • 2019-04-18
  • 2021-08-29
  • 2018-05-16
  • 1970-01-01
  • 2018-09-26
  • 1970-01-01
相关资源
最近更新 更多