decaporg / decap-cms

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

Save folder collection entries to single data file #3542

Open rdtclark opened 4 years ago

rdtclark commented 4 years ago

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.

tomrutgers commented 4 years ago

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.

rdtclark commented 4 years ago

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.

tomrutgers commented 4 years ago

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

rdtclark commented 4 years ago

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 commented 4 years ago

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.

tomrutgers commented 4 years ago

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

okonet commented 4 years ago

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/

stefanprobst commented 4 years ago

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:

erezrokah commented 4 years ago

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).

stefanprobst commented 4 years ago

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

stefanprobst commented 4 years ago

@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