decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Save folder collection entries to single data file

Open rdtclark opened this issue 5 years ago • 11 comments

Middleman has an excellent feature whereby you can generate all of your content via a single data file. If used in conjunction with Dynamic pages this becomes a beautifully simple yet powerful setup.

If Netlify CMS could support creating & editing these simple YAML or JSON entries that would be a highly leveraged way to author a static site while enabling easy access to other services & APIs.

I have considered more enterprise headless CMS solutions for example Prismic.io however it feels like overkill for this kind of use case.

This may be achievable with a new collection type "data" as a close cousin to the folder collection type.

Thank you for your consideration.

rdtclark avatar Apr 05 '20 16:04 rdtclark

Netlify CMS already supports YAML and JSON files, the Middleman starter includes examples of both markdown with middleman-blog and yml files with dynamic pages. If you want to edit your entries in a single file, have a look at the file collection.

tomrutgers avatar Apr 05 '20 17:04 tomrutgers

Thanks Tom.

I understood there is support for YAML and JSON already and the file collection but am I correct that you cannot create entries into a YAML file using the file collection?

I suppose an option if that is true is to create empty entries and mark them not visible until updated.

rdtclark avatar Apr 05 '20 19:04 rdtclark

You can make a yaml list with the list widget: https://www.netlifycms.org/docs/widgets/list/

tomrutgers avatar Apr 05 '20 20:04 tomrutgers

The list widget is an option but I am looking to create a number of products and need to add multiple images and fields for each. It would be ideal to keep a single products.yml file for other uses but I may have to concede in the end.

I had a conversation about this on the slack channel this week and it was suggested to put in a feature request.

Also as a beginner developer please excuse me while I get my feet wet.

I think the capability would be really useful across other generators like Gatsby for example.

Is this a realistic contender as a feature request?

rdtclark avatar Apr 05 '20 21:04 rdtclark

Update, I have re-modelled the data structure using your Middleman starter.

Thank you. Works wonderfully.

I would still like to make a feature request to support creating and editing with single data file, but accepting the limitation.

rdtclark avatar Apr 06 '20 08:04 rdtclark

Gotcha. I've updated the title for clarity. Glad to see it's working!

tomrutgers avatar Apr 06 '20 08:04 tomrutgers

Been looking for it in the context of sourcing the content to Gatsby using JSON: https://www.gatsbyjs.org/docs/sourcing-content-from-json-or-yaml/

okonet avatar Jun 10 '20 11:06 okonet

i also think a "single-file" collection type for list data would be great.

while "folder" collections are great for stuff like posts, and the "files" collection type for pages, i have been missing something for lists of data like "authors info".

to keep this in a single file the current workaround seems to be to have a file in a files collection with a single list widget inside. this however has a couple of disadvantages:

  • the list widget seems designed for short lists where source order of items matters. with larger lists it gets noticably laggy, and we have no UI for filtering and sorting list items.
  • while the relation widget now works with files collections, searchFields seem not supported

stefanprobst avatar Jun 12 '20 18:06 stefanprobst

Just making sure this isn't a duplicate of https://github.com/netlify/netlify-cms/issues/535

I think this feature can have two variations:

  1. As in issue #535 where a file is designed to model a unique non repeating data (like Private Policy, Contact Info, etc).

  2. As in this issue, a collection folder with multiple entries of the same type, written to the same file instead of multiple files. Resembles the list widget, but shows up as multiple entries in the CMS collection view (e.g. a products file).

erezrokah avatar Jun 15 '20 08:06 erezrokah

yes exactly -- it's somewhat related to https://github.com/netlify/netlify-cms/issues/531

stefanprobst avatar Jun 15 '20 10:06 stefanprobst

@erezrokah i've put together a hacky proof of concept how i think this could work. see https://github.com/netlify/netlify-cms/compare/master...stefanprobst:feat/single-file-collection

includes a simple demo, run with

yarn
yarn build
cp -r packages/netlify-cms/dist dev-test/dist/
npx netlify-cms-proxy-server
npx serve dev-test
open http://localhost:5000/test

stefanprobst avatar Jun 18 '20 09:06 stefanprobst