decaporg / decap-cms

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

Widgets and Data outside the config #239

Closed smakinson closed 6 years ago

smakinson commented 7 years ago

- Do you want to request a feature or report a bug? This is a question and potentially a feature request.

I am interested in using the CMS with Hugo. It looks like there are quite a few more widgets in the src than are documented so there may be a way to do what I am stewing on already, but here is what is on my mind:

I am looking for an appropriate way to create a select control in CMS that contains the taxonomies used in a Hugo site. I see there is a SelectControl that could be used. I see if I set the widget to "select" and provide an options property it shows up. An array of strings works to populate the options, but an array of objects such as: [{label: "LABEL", value: "VALUE"}] doesn't seem to add the text as expected.

What I am thinking of is feeding the widget a path to a json file that contains the options array could be a solution. Does this exist?

I found this discussion on the Hugo site that may allow the json to be generated, thought i have not joined that discussion yet.

https://discuss.gohugo.io/t/custom-output-content-types/4584/4

I suppose using Hugo to generate the config for the CMS could potentially work as well, but may need some other changes since the config could change while using the CMS.

Thanks for the discussion.

erquhart commented 7 years ago

@smakinson if an array of objects would serve your use case, that's the easiest path. Can you explain what you'd expect to do with an array of objects in the select widget?

smakinson commented 7 years ago

@erquhart Hey there! Thanks for looking into this. Something like this could be an example:

Say Hugo has a type of content called authors that I would like to have in a widget such as a dropdown in a CMS view for something like articles. The idea would be that as the CMS modified the content for authors, Hugo would generate a new json file using: https://gohugo.io/extras/output-formats/

Then when the the CMS is on the view for adding or editing the articles the widget would load that json file that was generated to provide the options. It could be a dropdown or possibly something else. I do see one potential issue, the lag time for generating the updated json if one were to quickly add an author then go to add an article. Perhaps a refresh button for widgets using this source could help? As I type his particular example it also makes me thing when it comes to authors in particular, showing the people who have access to the repo could also be useful, but thats another subject I suppose.

As far as the values in the list of options they could end up being the actual name of the author that would be viewed on the live site or potentially some sort of id for cross referencing back to that json. The idea is to sorta pretend there is a database behind this.

Does that make sense? Am I missing any other potential issues?

erquhart commented 7 years ago

It sounds like the relation widget may work for you. It's not documented, but I gave a quick explanation here: https://github.com/netlify/netlify-cms/issues/192#issuecomment-311133616

The idea is to have an authors collection, and then select one of those authors from your article (via dropdown). Any chance this does what you need?

smakinson commented 7 years ago

Cool. Hard to be 100% sure, but it does sound like it would work if it can be set up to relate any collection into a create/edit view for another collection. In fact it sounds like it is potentially better.