decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.95k stars 3.05k forks source link

Remove requirement for 'title' field in folder collections #1802

Closed honeyspoon closed 6 years ago

honeyspoon commented 6 years ago

I'm not sure if this should be considered as a feature request or as a bug.

General

The 'title' field seems to be required in folder collections according to the documentation

The config file checks that requirement at initialization ever since release 2.0.

This requirement was put in place because the generated slug uses the 'title' field.

My problem

My particular use case of the cms would require me having a folder collection that references JSON files. I don't want to add a title property for in my files. I already have a field that could be used as an identifier 'uid'

config.yml

here is my configuration for the affected folder collection

  - name: "author"
    label: "Authors"
    folder: "content/authors"
    create: true
    slug: "{{uid}}.json"
    fields:      
      - {label: "UID", name: "uid", widget: "string"}
      - {label: "Name", name: "name", widget: "string"}
      - {label: "Profile picture", name: "image", widget: "image"}
      - {label: "Website", name: "url", widget: "string"}
      - {label: "Bio", name: "bio", widget: "string"}
      - {label: "Social Urls", name: "social", widget: "list"}

As you can see, I don't have a title field. I also have defined a custom slug that uses my own identifier.

This current configuration gives me an error message: Error loading the CMS configuration Config Errors: 'collections[1]' must have a field that is a valid entry identifier Check your config.yml file.

Possible solutions

Adding a title field to my collection

I can add a title field to my collection and that would fix the error message, but it would add a field that I have no need for and that I cannot leave blank for items in my collection. Seems like a bad practice.

Removing the requirement for 'title' field when using cutom slug

Since this requirement is only here to ensure the slug will work (not sure if its the only reason), we could simply not check it when a custom slug is defined.

Changing requirement for a custom identifier

The current code checks if the collection has identifier fields. The only two identifier fields are currently 'title' and 'path' source I could specify my own identifier field like this feature request suggests and it would add my field to 'title' and 'path' as an indentifier. This would fix the error.

Change perspective

Maybe I'm using the cms for something it was not indented to do and I should not be able to edit these kind of files.

Contex

netlify-cms v 2.1.2

kennedyrose commented 6 years ago

We've run into the same problem. We usually just change the ID field to "title" but it feels a little hacky and could lead to some confusion during development.

ascorbic commented 6 years ago

To be clear, #1543 isn't a feature request: it's a working PR that adds support for this (or at least it was when I opened it, it probably needs updating now)