Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content in subfolders… #513

Closed
kevinfoerster opened this issue Aug 5, 2017 · 77 comments · Fixed by #2897
Closed

content in subfolders… #513

kevinfoerster opened this issue Aug 5, 2017 · 77 comments · Fixed by #2897

Comments

@kevinfoerster
Copy link

it is not very obvious and maybe impossible, ist there a way to have collections with subdirectories?

currently I have a folder called products and in there several product folders with their index.md respectivly.

the title of the folder corresponds with the title in each index.md

├── products
│   ├── orange
│   │   └── index.md
│   ├── quitte
│   │   └── index.md
│   └── zwetschge
│       └── index.md

netlify-cms does not parse the subfolder and/or does not list any content.

the collection is configured using this folder: "src/pages/products/

is that even possible?

@tortilaman
Copy link
Contributor

tortilaman commented Aug 5, 2017

Netlify CMS doesn't currently support sub-folders. I think there has been some discussion around this though, and I'm sure it would be a welcome improvement.

If you want this final folder structure, I might suggest using metalsmith or gulp to create such a structure from a structure netlify-cms will work with. I'm currently using metalsmith, and here's what I get.

Starting Files:

├── posts
    ├── page1.md
    ├── page2.md
    ├── page3.md
    ├── page4.md

Finished Files:

├── posts
    ├── page1
    │    └── index.html
    ├── page2
    │    └── index.html
    ├── page3
    │    └── index.html
    ├── page4
    │    └── index.html

@kevinfoerster
Copy link
Author

ok…

@erquhart
Copy link
Contributor

erquhart commented Aug 6, 2017

@kevinfoerster you can use a "file" type collection, and use the full path to each file. Here's an example: https://github.com/netlify/netlify-cms/blob/master/example/config.yml

Having to repeat the config for each file is not ideal, so @tortilaman's approach is ideal.

@erquhart erquhart reopened this Aug 17, 2017
@erquhart
Copy link
Contributor

Finding a way to support this is worthwhile, reopening.

@kalinchernev
Copy link
Contributor

kalinchernev commented Aug 17, 2017

Just to say from personal experience, indeed having a step which flattens the files works well at this stage.
While trying to figure this question myself, I also found this test which has folder_based_collection in the config. Maybe at some stage it was already an idea, but it's not implemented.
As I don't know how exactly the paths are parsed, just throwing ideas, maybe support for a regex or glob patterns in the existing configuration property could be an option.

@erquhart
Copy link
Contributor

erquhart commented Sep 7, 2017

I'm wondering if we can resolve this with more advanced slug handling, maybe as a part of #445.

The idea would be to allow the "slug" property to optionally be a path, which would be appended to the folder collection's base path. So to serve @kevinfoerster's example, it could look like:

name: products
folder: products
slug: /{{slug}}/index.md
...

Thoughts?

cc/ @marksantoso

@marksantoso
Copy link

marksantoso commented Sep 7, 2017

Hi @erquhart this would result in a collection with many items. Providing not much structure for the user.

E.g. Say you have a collection for 'pages', if you were to use the slug to manage subpages of pages you would end up with 1 collection with multiple pages, but no easy way to distinguish where they sit in the page hierarchy. subpages would sit in the same interface as their parent pages.

This would also mean all items in this pages collection would hold the same fields, not ideal if various pages need different fields.

Possibly another config type is required: Collections with subcollections?

@erquhart
Copy link
Contributor

@marksantoso this is specifically for repeatable content - items that have the same general format and share the same field structure, e.g. blog posts. For distinct pages as you're describing, you'd still want to specify individual files.

@criticalmash
Copy link

Hi, trying out Netlify-cms for the first time and having the same issue. My build script (using Assmble.js 0.24.3) uses a source directory where all my content is organized hierarchically. This hierarchy determines the paths of the generated html files, and the navigation (with drop-downs, sidebars, etc.)

Prose.io seems to handle this quite well, showing a collection's files and directories and allowing the user to define the path right in the interface. I'm wondering what's preventing Netlify-cms from doing the same?

Having one flat directory for all my pages is a nonstarter. I'd love to have all the additional features this CMS provides (workflows, previews and most importantly authentication) but my whole way of building websites depends on using subfolders.

@tech4him1
Copy link
Contributor

@criticalmash Have you thought about making each folder it's own collection?

@criticalmash
Copy link

@tech4him1 That might work! Thanks. It would mean creating a new collection every time the client wants a new directory. But in that case, I'd need to adjust the main nav anyway.

@ChrisChinchilla
Copy link

Hey all, I was wondering if this also included images stored in sub-folders of your media_folder?

@erquhart
Copy link
Contributor

erquhart commented Jan 3, 2018

I answered this in Gitter, but for posterity, assets need to be stored directly within the media folder. We do intend to allow multiple asset collections in the future.

@DSchau
Copy link

DSchau commented Jan 16, 2018

Hi @erquhart, excellent work on Netlify CMS (and the entire Netlify team, as well) -

I can open a quick issue, but I think this is actually the same issue as @kevinfoerster.

We store our blog posts (and authors) in nested folders, like

src/
  posts/
    2017/
    2018/
    ...

and then inside of each folder, we use the slug title as a folder. We do this so we can easily add other data (images mostly, for now!) while keeping the underlying file structure pretty clean and organized. This leaves us a folder structure like:

2018/
  migrating-from-wordpress-to-markdown/
    index.md

As best as I can tell, I can not create this structure currently with netlify-cms. I believe this is primarily because the folder attribute does not currently support templating like the slug attribute. For example, I tried the following, but the resulting folder structure is literally the path without the curly braces replaced.

collections:
  - name: blog
    label: Blog
    folder: "src/posts/{{year}}/{{slug}}"
    create: true
    extension: markdown
    format: frontmatter
    fields:
      - { name: author, label: author }
      - { name: category, label: category, widget: "select", options: ["JVM", "JavaScript", "Devops", "Company"] }
      - { name: date, label: Date, widget: date }
      - { name: title, label: title }
      - { name: "body", label: "Blog post content", widget: "markdown"}

Is this a feature that you think is worthwhile? If so, I'd love to chip in and help get this built out, but I'm not quite sure where to start. Been perusing this repo in an attempt to start to get up to speed.

Any advice on that would be hugely appreciated!

Thanks for your time.

@erquhart
Copy link
Contributor

erquhart commented Jan 20, 2018

@DSchau yep, that's a great point. Also, @marksantoso, I now see I misread what you meant.

Sounds like folder collections should be able to accept a collections field themselves. This is even more workable when you consider that YAML supports repeating nodes, so you can have reusable chunks of configuration when a site has a complex hierarchy of pages that are structurally similar.

That's the direction that makes the most sense at the moment. I'd love feedback from both of you in light of your own use cases.

cc/ @tech4him1 @Benaiah @talves @biilmann - especially interested in reasons not to go this route.

Note that I'd expect this to mostly affect the configuration and UI surfaces, the underlying collections model would remain flat.

@tech4him1
Copy link
Contributor

I see two separate feature requests here (that I think should be split out into separate issues):

  1. Nesting collections in the UI.
  1. Keeping each entry in a /entry-slug/index.md format, instead of /entry-slug.md:

@erquhart
Copy link
Contributor

erquhart commented Apr 4, 2018

@tech4him1 agreed, we should split off "nesting collections in the UI". #1156 is in that vein, maybe we could expand that to cover the full nested collections concern.

Possible short term solution

Working on a solution for single level nested directories, it's shaping up like this:

folder: my/folder
slug: {{slug}}/whatever

Which would output something like my/folder/post-title/whatever.md.

  • folder works as it currently does
  • slug can now have a slash separating directory from file
  • more than one directory in slug, e.g. {{slug}}/extra/index, will error out
  • leading and trailing slashes are ignored
  • all current placeholders work throughout slug, so you can do:
    slug: {{slug}}/{{year}}-{{month}}-{{day}}-{{slug}}

Proposed long term solution

I'd like to see us simplify this whole thing down to a single path property, which accepts placeholders throughout:

# The most explicit approach would be defining a full path:
path: my/folder/{{slug}}/index.md

# But you can keep it simple and we'll give you a derived slug and default
# extension/format (markdown):
path: my/folder

# Types are inferred for recognized extensions
path: data/stuff.yaml

# One additional field, `format`, is accepted for unrecognized extensions or
# formats that don't match the extension:
path: data/stuff.myext
format: json

# Now you can do whatever you want:
path: nested/dir/{{slug}}/index.pt.md

Thoughts? Especially looking for reasons why these solutions might not work.

@erquhart erquhart self-assigned this Apr 4, 2018
@tech4him1
Copy link
Contributor

tech4him1 commented Apr 10, 2018

@erquhart As a technical description of how the path property would work, so it's easier to see any problems. Let me know if it doesn't match what you are thinking.

  1. Sanitize and replace all placeholders
    • nested/dir/{{slug}}/index.pt.md --> nested/dir/entry-title/index.pt.md
  2. Split into folder and filename at last slash.
    • nested/dir/entry-title/index.pt.md --> [nested/dir/entry-title, index.pt.md]
  3. Split filename into extension to infer format.
    • This is the part I'm not sure about.
    • What if you actually did want a file without an extension? We can't always assume that without an extension on the end, it's actually a folder name, not a file name (e.g. my/{{slug}}).
    • What do we do in the case of multiple extensions (e.g index.pt.md)? Do we just check the last extension and try to infer from that? Right now, with the explicit extension property we force the user to set the format manually, but I think we can just infer from the last extension. @Benaiah?
  4. Use extension to filter directory.
    • This is where we can't just use the last extension. If I have a directory of en.md and cr.md files, I may only want one set to show up at a time.

@denisnazarov
Copy link

I am also seeking this feature for a Wordpress blog I'm migrating to NetlifyCMS.

@jimmyangel
Copy link

@erquhart , this feature ({{slug}}/whatever) along with images relative to content would work really well with Gridsome too: storing collections in separate, self-contained subdirectories is a really nice way to organize a site with large collections. I could help with implementation if you point me in the right direction.

Thanks,

Ricardo

@tcg
Copy link

tcg commented Oct 29, 2019

Not intending to pile on. Google brought me here, and I thought it might be worth dropping in: I was very excited to fire up Netlify CMS, and then saw most of my posts missing. I prefer to use a structure like blog/{post-slug}/index.md (a Hugo site) and I always store post-specific assets alongside the post, in its folder.

I definitely understand how that makes media management and configuration a potential nightmare, but I'd looooooove the ability to do this.

I'll definitely have a look around and see if I have time to try to contribute something, if that's a welcome feature for Netlify CMS.

@erquhart
Copy link
Contributor

Loud and clear. This is literally up next, hold tight.

Sent with GitHawk

@erquhart erquhart assigned erezrokah and unassigned erquhart Nov 7, 2019
@theBliz
Copy link

theBliz commented Nov 11, 2019

I'm confused.. what's the status of this issue??
Is it currently possible or not to have .md files organized in sub-folders?
Atm I can only see .md files in my root folder..

@hacknug
Copy link

hacknug commented Nov 12, 2019

This is literally up next, hold tight.

@theBliz that's the status ☝️

@theBliz
Copy link

theBliz commented Nov 12, 2019

This is literally up next, hold tight.

@theBliz that's the status ☝️

I've seen it but "next" does not specify a timeframe. Are we talking about a week or a month?

More precisely, should I apply one of the workarounds suggested in the thread or should I wait a few days?

@erquhart
Copy link
Contributor

If I had to throw out a timeframe, I’d say a month. That’s an estimate, not a commitment.

Sent with GitHawk

@theBliz
Copy link

theBliz commented Nov 16, 2019

thanks @erquhart 👍 I'll check some of the workarounds in the meantime

@MildTomato
Copy link

Just started using Netlify CMS, and this was literally the first thing I was trying to do
Kudos to everyone who was pushing for this feature :)

@omfgnuts
Copy link

omfgnuts commented Dec 13, 2019

@erquhart Heyo! I see this issue is fixed, any info on how we can get it and use it? Sorry for being annoying, but this is kinda urgent for me!

Edit: It's already in beta, switch to netlify-cms@2.10.0-beta.4

@themre
Copy link

themre commented Jan 19, 2020

@omfgnuts can we see how we can use this feature? a lot of discussion was so I'm a bit confused which one it is :) thanks!

@nonlinearcom
Copy link

nonlinearcom commented Jan 19, 2020

I think this feature is only compatible with the editorial workflow, or at least that's how I got it working.

@erezrokah
Copy link
Contributor

Hi @nonlinearcom with the latest version of the CMS this is also supported with the simple workflow.

@themre
Copy link

themre commented Jan 19, 2020

hi @erezrokah are there any docs about this? maybe would be nice also for others to see this. thanks!

@erezrokah
Copy link
Contributor

Hi @themre docs are under the beta section https://www.netlifycms.org/docs/beta-features/#folder-collections-path

@lrq3000
Copy link

lrq3000 commented Dec 20, 2020

For those who need fully recursive nested collections without a predefined limit on the level/path template, check out https://www.netlifycms.org/docs/beta-features/#nested-collections (thanks to @erezrokah once again!)

@jace-ys
Copy link

jace-ys commented May 14, 2021

I came across this issue while trying to integrate Netlify CMS with my Hugo site, and I ended up using both path and nested features to achieve my dream setup 🎉

Thanks to everyone who chipped in / worked on this, really great work ❤️

@TravisBrace
Copy link

TravisBrace commented Dec 1, 2022

Wanted to see if there was anyway I could help with this. Beta nested feature just shows empty folders.

Found this page from a DDG search. Looks like it should still be open. Trying the beta nested feature the folders show up but some directories are empty.

Using Jekyll I can set the permalink on these pages and give whatever permalink to build. But unless they're in the _pages collection folder they can't be reached and edited through the CMS

Content structure is like

posts
|---- blog1.md
|---- blog2.md

pages
--|---- page1.md
--|---- page2.md
--|---- page3.md
--subgroup (about us)
----|---- subpage1(specific about us feature).md

Thank you all for the hard work this is such a great tool to be using! Want to be able to implement this and spread the joy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.