File being deleted after publish from Netlify CMS

Hi my Netlify site name is https://kind-kalam-64dad8.netlify.app/ and github link is : GitHub - kalariyogi/kalariyogi-11ty-netlify-cms: Static site with eleventy and netlify cms
I am trying to update the config.yml to edit the index.njk file so I am using file collections. When I update the fields in Netlify CMS the file gets deleted.

Below is my config.yml file

backend:
name: git-gateway
branch: main

media_folder: “_site/images/uploads”
public_folder: “/images/uploads”

collections:
  - name: "posts"
    label: "Posts"
    folder: "posts"
    create: true
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
    fields:
      - { label: "Layout", name: "layout", widget: "hidden", default: "layouts/post.njk" }
      - { label: "Title", name: "title", widget: "string" }
      - { label: "Description", name: "description", widget: "string" }
      - { label: "Date", name: "date", widget: "date", default: "" }
      - { label: "Post Body", name: "body", widget: "markdown" }
      - { label: "Featured Image", name: "featuredImage", widget: "image" }
  - name: "pages"
    label : "Pages"
    files:
      - label: "Home Page"
        name: "index"
        file: "index.njk"
        fields:
          - { label: "Hero Text", name: "heroText", widget: "string" }
          - { label: "Hero Description", name: "heroDescription", widget: "string" }
          - { label: "Hero Image", name: "heroImage", widget: "image" }
          - { label: "Hero body", name: "body", widget: "markdown" }

Here is my index.njk file

---
layout: layouts/base.njk
permalink: /
heroText: Yoga
heroDescription: Yoga for the mind, body and soul
heroImage: none
---

<div class="jumbotron jumbotron-fluid" style="background-image: url("{{heroImage | url}}");">
  <div class="container">
    <h1 class="hero-text display-4">{{heroText}}</h1>
    <p class="lead">{{heroDescription}}</p>
  </div>
</div>
<div class="container">
  {{ content | safe }}
</div>

Would really appreciate some help with this problem.

Thanks
Nikhil Pereira

hi there, this was filed in the wrong area so it didn’t get the attention it needs! I have moved it, so hopefully someone has some input for you.

You can’t edit the frontmatter of a njk file and at the same time keep its html content, simply because the CMS only outputs data. It has no way of understanding or parsing anything other than data (yaml, json etc). I recommend you store the data in a separate file and load it in your index (instead of using frontmatter in the index). As you’re using eleventy, it’s probably easiest to use a json format (although you can configure yaml just as wel).