3

I'm trying to get my head round using Netlify CMS with Hugo ssg.

I use:

netlify-cms@1.0
hugo@0.29

I have a simple netlify-cms config.yml with two collections: posts and authors.

  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"}

The docs distinguish two collection types, of which I assume i should choose file collection, as I'd like to hold the authors data in one file.

I'd like to be able to add authors via admin dashboard and save it to file in data folder. The docs doesn't provide an example of how should the file holding the authors look like (Or does the cms make it automatically?).

I encounter an error with my current config. When I'm saving the "New Author" i get this:

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

Why do i get this error?

talves
  • 13,993
  • 5
  • 40
  • 63
Sebastian
  • 1,225
  • 1
  • 16
  • 27

1 Answers1

7

Your authors file needs to be under a top-level collection. Also, if you want to be able to add multiple authors to the file, you need to wrap the "name" and "about" widgets in a "list" type widget.

Example:

  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 docs for file collections: https://www.netlifycms.org/docs/collection-types/#file-collections

CMS docs for list widgets: https://www.netlifycms.org/docs/widgets/#list

tech4him
  • 970
  • 5
  • 20
  • This answer would be even better with a referenced config for the Hugo data file. – Rogelio Apr 03 '22 at 19:28
  • This doesn't seem to be working for me and I'm not too sure why. I've copied a similar config format as in your answer, but for me when I navigate to this section on the Netlify CMS interface, there is just an empty collapsible list showing. There is an add entry button but nothing works when it is clicked. The YAML data file I am trying to access through the CMS already exists and has several entries in it added manually by me, and works correctly as one of my pages renders based of this file. Any ideas or do you suggest I open a separate question with more detail? – Lushawn Sep 01 '22 at 14:10
  • Update on my issue: I found it was that my yaml file itself wasn't structured correctly. If someone needs help @ me and I will make a post about it. – Lushawn Sep 01 '22 at 15:29