Netlify-cms: Recursive folder collections

Created on 20 Dec 2020  路  7Comments  路  Source: netlify/netlify-cms

This is a follow-up to #513.

Folder collections now allows to walk through a specific level of folders to retrieve content. However, it has two major limitations:

  • The number of levels (levels depth) is limited.
  • It's not obvious how new pages can be created under a specific subfolder.

A natural scheme for organizing multilevel content is by creating as many subfolders as there are levels of navigation. One concrete common use case is a documentation project. The current implementation does not allow that if I'm not mistaken.

To implement multilevel/recursive walking in NetlifyCMS, it would require at least 3 parts:

  • a new API for the path field to allow for an unlimited number of folders. Could be a regular expression? Or simply the path to the root folder for the collection and just another switch to enable complete recursive walk.
  • the NetlifyCMS UI would need to display levels in some way. A simple way would be to simply indent entries according to the number of levels they are.
  • to manage the creation of new pages. A simple way would be to allow the use of "{{dirname}}" as the default value in fields definitions, so the user could create a field like this to manage the folder: - { name: category, label: Category, default:"{{dirname}}", widget: string }.
feature

Most helpful comment

All 7 comments

Closing this issue, If you have a specific use case the beta feature doesn't address please open a new one

@erezrokah Ah I didn't see this feature was in the Beta section in the docs! Thank you so much for your awesome work on this feature!

I'm still running into some issues but so far it at least detects all my files, even those that are not named index.md, so I guess the discussions here and here are outdated now?

The only issue I have is that when I navigate in NetlifyCMS in the subfolders (should we call those "subcollections"?), no document is shown, not even the index.md files. But they are correctly detected when navigating the root collection, just unordered. I'm still experimenting but so far to no avail. Do you have any suggestion on how I can debug this (get more verbose infos from NetlifyCMS maybe?).

Hold on I may have found why.

Ok I have found why, it's because I didn't respect the proper organization as mentioned here but not in the doc, which is to have one index.md file per subfolder, and any subpage should get its own subfolder. I can work around that no problem.

What is strange is that even when not respecting the expected file structure, the nested collection does show all files (although not in subcollections), and they can be opened! However the parent path gets all messed up, as it always expect the file to be "{{parent}}/index.md", which is what tipped me onto fixing my issue. It seems like the nested collections are close to support arbitrary file structures, there's just some gaps that need to be filled (is that why it's still in beta?). I unfortunately am not good enough with javascript to contribute a PR...

Just a heads up for others using Gatsby: in the doc the path meta field uses widget type string whereas in your example repo it's parent, which is much better! However this widget type is only present in the latest versions of netlifyCMS, which is not the one currently used in gatsby-plugin-netlify-cms so I had to overload the plugin with my own admin.html page.

However this widget type is only present in the latest versions of netlifyCMS

The widget is not part of the CMS core and published separately here:
https://netlify-cms-widget-parent.netlify.app/netlify-cms-widget-parent.js

note this is more of an experiment/example and not officially supported.

Ahhh I see, thank you very much for the clarification!

I argue this widget type should be integrated ASAP! It's very necessary to manage nested collections with a good user experience! Great job once again! :D

Was this page helpful?
0 / 5 - 0 ratings