HUGO

Transform a string into a collection + netlifyCMS

Hi
I have a blog where I have an author field in the blog posts:

Before, I used to enter an author as a string field. But my new feature permits to select an author, each author has its own .md file (authors/john_doe.md for example)

That’s great and now, I can select the author and since there is a twitter_url and a description in each author md file, I used it to make a nice section about the author of the blog post at the end of each post.

I had to transform every blog post like that:

author: John Do
to

author:
  - John Do

to make it works

I thought everything would work fine, but now, when I use netlify-cms, every time I create a blog post or update one, it rechanges to author: John Do

So every time I create or change a blogpost, I need push a hotfix on github.

Is there a way to fix this problem?

here is my config.yml

collections:
  - name: "blog"
    label: "Post"
    folder: "site/content/blog"
    create: true
    fields: 
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Intro Blurb", name: "description", widget: "text"}
      - {label: "Image", name: "image", widget: "image"}
      - {label: "Body", name: "body", widget: "markdown"}
      - label: "Author"
        name: "author"
        widget: "relation"
        collection: "authors"
        searchFields: ["title"]
        valueField: "title"
        displayFields: ["title"]
      - label: "Category"
        name: "category"
        widget: "relation"
        multiple: true
        collection: "categories"
        searchFields: ["title"]
        valueField: "title"
        displayFields: ["title"]
        required: false
  - name: "authors"
    label: "Author"
    folder: "site/content/authors"
    create: true
    fields:
      - {label: "Author Name", name: "title", widget: "string"}
      - {label: "Description", name: "description", widget: "string"}
      - {label: "Image", name: "image", widget: "image"}
      - {label: "Twitter URL", name: "twitter_url", widget: "string", required: false}
      - {label: "Website URL", name: "website_url", widget: "string", required: false}

This is a question for the netlify-cms forum.

1 Like

I headed to the Netlify-CMS Slack thanks to you, but since my question targets people that uses both technologies, I will let the question until I get a solution :slight_smile:

This topic was automatically closed after 32 hours. New replies are no longer allowed.