Skip to content

Problems with using dynamic media_folder name #3723

@smashercosmo

Description

@smashercosmo

Describe the bug
This is how I define my posts collection

collections:
  - label: Posts
    label_singular: post
    name: posts
    folder: content/posts
    media_folder: '/{{media_folder}}/posts/{{filename}}'
    public_folder: '{{public_folder}}/posts/{{filename}}'
    format: frontmatter
    create: true
    identifier_field: title
    fields:
      - {label: Title, name: title, widget: string}
      - {label: Cover image, name: cover, widget: image, required: false}
      - {label: Body, name: body, widget: markdown}

as you can see media_folder name is based on the filename. But the problem is that when you create post file doesn't exist, so images in markdown is written with wrong path.

How to reproduce
Here is reproduction repository
https://github.com/smashercosmo/folder-collections-media-and-public-folder-issue

  1. run npm run develop
  2. open http://localhost:8000/admin/
  3. press new post
  4. fill the form and upload an image
  5. press publish

Expected behavior
you should see correct image path in frontmatter

---
cover: /img/posts/new-post-name/image.jpg
---

Actual behavior
you will see this instead

---
cover: /img/posts/image.jpg
---

Applicable Versions:

  • Netlify CMS version: 2.12.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions