Slug shows up either as ----.md or "--_"_.md

I’ve pretty much copied the config.yml from the docs, but I get strange filenames. At first they started as ----.md and counted, ie —1.md, —2.md, etc. At one point I got the slug to show just the title, but I can’t reproduce it. Now it shows up as "—".md and counted, ie "—_“1.md, "—”_2.md, etc. with the quotation marks in the filename. I’d like to see something like 2020-04-16-my-blog-title.md.

What am I doing wrong?

backend:
  name: github
  repo: username/myrepo
  branch: master # Branch to update (optional; defaults to master)

# This line should *not* be indented
publish_mode: editorial_workflow

# This line should *not* be indented
media_folder: "/static/img/uploads" # Media files will be stored in the repo under images/uploads

collections:
  - name: "blog" # Used in routes, e.g., /admin/collections/blog
    extension: md
    label: "Blog" # Used in the UI
    folder: "posts" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: “{{year}}-{{month}}-{{day}}_{{slug}}”
    fields: # The fields for each document, usually in front matter
      - {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Description", name: "description", widget: "text"}
      - {label: "Font Awesome Icon", name: "icon", widget: "string"}
      - {label: "Featured Image", name: "thumbnail", widget: "image", required: false}
      - {label: "Body", name: "body", widget: "markdown"}

slug:
  encoding: "ascii"
  clean_accents: true
  sanitize_replacement: "_"

Looks like this is the second Flask-FlatPages / Flask-Frozen problem I’ve been able to answer myself. The reason is rather obvious once you figure it out.

  1. Flask-Frozen serves everything in the /build directory. In the standard case this-is-fine™. However if you want to integrate with Netlify CMS you need to add a /admin directory to your root. How do you do that if your /build directory is overwritten every time you run python freeze.py, you ask?

  2. Create an admin blueprint for the index.html and the config.yml file. This creates /build/admin that Netlify CMS can read. Solv’em Prob! Not so fast…

  3. Jinja2 syntax. Because we are serving this as if it’s a typical flask file, anything like {{year}} is expected to have a value passed into the template. If it’s not, Jinja interprets "{{year}}-{{month}}-{{day}}{{slug}}" as –.md and Netlify is smart enough to add a counter to duplicate filenames. The reason I didn’t realize this sooner is because I didn’t look at the /build/admin/config.yml file. I only looked at the config.yml in the blueprint folder. It was clear as day slug: "---" in the file or the various iterations I attempted, such as slug: "--_".

  4. What’s the solution? Escaping those curly brackets! The easiest way to do that for config.yml is to add {% raw %} … {% endraw %} to your config.yml file (See Below)

In my experiment with Netlify CMS, Flask-Frozen and Flask-FlatPages I ran into a number of silly issues, so I’m not quite sure how I feel about it. I could try Pelican, but I quite like the freedom Flask-Frozen and Flask-FlatPages provides. Something to mull on.

{% raw %}
backend:
  name: github
  repo: username/myrepo
  branch: master # Branch to update (optional; defaults to master)

# This line should *not* be indented
publish_mode: editorial_workflow

# This line should *not* be indented
media_folder: "/static/img/uploads" # Media files will be stored in the repo under images/uploads

collections:
  - name: "blog" # Used in routes, e.g., /admin/collections/blog
    extension: md
    label: "Blog" # Used in the UI
    folder: "posts" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: “{{year}}-{{month}}-{{day}}_{{slug}}”
    fields: # The fields for each document, usually in front matter
      - {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Description", name: "description", widget: "text"}
      - {label: "Font Awesome Icon", name: "icon", widget: "string"}
      - {label: "Featured Image", name: "thumbnail", widget: "image", required: false}
      - {label: "Body", name: "body", widget: "markdown"}
{% endraw %}

awesome - thank you so much for sharing!