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

New document in a subfolder with existing docs creating index.md

Open pranaysahith opened this issue 5 months ago • 1 comments

Describe the bug

New document in a subfolder is creating an index.md instead of non-index markdown.

To Reproduce

  1. Go to a sub folder in Decap CMS
  2. Click on New document
  3. Enter, title, body and save
  4. It creates an index.md file and messing up the sub directory name.

Expected behavior

It should create a new markdown with a slug.md ( from title)

Screenshots

Applicable Versions:

  • Decap CMS version: 3.8.4
  • Git provider: Azure
  • OS: Ubuntu 24
  • Browser version: Chrome Version 141.0.7390.108 (Official Build) (arm64)

CMS configuration

collections:
  - name: "docs"
    label: "docs"
    folder: docs-site
    create: true
    extension: 'md'
    editor:
      visualEditing: true
    summary: "{{dirname}}/{{filename}}.{{extension}}"
    fields:
      - { label: "Title", name: "title", widget: "string", required: false }
      - { label: "Body", name: "body", widget: "markdown", required: false }
      - { label: "Tags", name: "tags", widget: "list", required: false }
    nested:
      depth: 10
      subfolders: false
      summary: '{{slug}}'
    meta: { path: { label: 'Path', widget: string, index_file: 'index.md' } }

Additional context

pranaysahith avatar Sep 17 '25 22:09 pranaysahith

I’m also facing the exact same problem. The issue seems to boil down to the index_file attribute being static rather than dynamic.

meta: { path: { label: 'Path', widget: string, index_file: '_index' } }

This will always write a new file to the path called "_index.md". If I create two files in the same sub folder and publish both, the _index.md will always be overwritten by the last published file.

At present it is impossible to create new non-index files.

Possible Solution: index_file is able to accept a slug/f-template e.g. {{filename}}, {{slug}}.

Use Case: We are building a documentation site for non-technical staff to be able to add new documentation. We are using Docusaurus which uses a flat folder structure (many .md files per folder, indexing handled using category.json), so this feature is highly desirable for us. This comment here from previously closed issue seems to be touching on what I am describing. I understand the current logic assumes a single _index.md file, but is it possible to extend this?

Additional information:

Decap CMS version: ^3.0.0 via unpkg (3.9.0 currently) Git provider: GitHub OS / Browser: MacOS, Chrome CMS config excerpt:

collections:
  - name: folder1
    label: Folder1
    folder: docs/folder1
    create: true
    extension: md
    slug: {{id}}
    nested:
      depth: 5
      summary: {{dirname}}
      subfolders: false

    fields:
      - { name: id, widget: string }
      - { name: title, widget: string }
      - { name: body, widget: markdown }

    meta: { path: { widget: string, label: "Path", index_file: slug } }

Folder set up:

docs/
└── folder1/
    ├── file1.md
    ├── subfolder1/
    │   ├── _category_.json
    │   ├── file1.md
    │   ├── file2.md
    │   └── file3.md
    ├── subfolder2/
    │   ├── _category_.json
    │   ├── file1.md
    │   ├── file2.md
    │   └── file3.md
    └── subfolder3/
        ├── _category_.json
        ├── file1.md
        └── file2.md

I'd be willing to have a go at this myself if I am capable. Is the impacted file here?

elisjudge avatar Nov 19 '25 05:11 elisjudge