Collection configuration for posts in year/month folder structure

Hello, I’m new to Netlify CMS. I need help configuring the collections to read and write posts in a blog folder structure that resembles {{year}}/{{month}}/{{slug}}.

I have a site built with Hugo that supports three languages. The language code appends to the URL as www.example.com/es/ but the default is English.

The blog entries in Hugo’s file structure exist in the content folder under a folder called news and are organized by additional sub-folders by year and month, e.g., content/news/2020/06/slug-for-article.md. All articles have identical file locations and slugs except the language code is appended before the .md file extension, e.g., slug-for-article.en.md, slug-for-article.es.md.

I was able to setup the CMS but am unsure how to configure collections so that:

  1. The collections show existing articles in the {{year}}/{{month}} folders.
  2. New articles are created in the appropriate {{year}}/{{month}} folders.

Here’s a sample of the collections configuration for an English label:

collections:
  - label: "News (English)"
    name: "news_english"
    folder: "content/news"
    path: "{{year}}/{{month}}/{{slug}}"
    preview_path: "news/{{year}}/{{month}}/{{slug}}"
    create: true
    filter: {field: "language", value: "en"}
    fields:
      - {label: "Language", name: "language", widget: "select", options: ["en", "es", "ko"]}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Body", name: "body", widget: "markdown"}`

@cptncrnch Welcome to the Netlify Community. I don’t know the answer to your question, but I changed the topic from netlify-newbie to netlify-cms, as that seemed to fit better.

Hi @cptncrnch and welcome, @gregraven thanks for clarification.

@cptncrnch, I think you would need an extra piece of configuration to save files with the relevant locale:

collections:
  - label: "News (English)"
    name: "news_english"
    folder: "content/news"
    slug: "{{fields.title}}.{{fields.language}}"
    path: "{{year}}/{{month}}/{{slug}}"
    preview_path: "news/{{year}}/{{month}}/{{slug}}"
    create: true
    filter: {field: "language", value: "en"}
    fields:
      - {label: "Language", name: "language", widget: "select", options: ["en", "es", "ko"]}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Body", name: "body", widget: "markdown"}`

That should save files under content/news/2020/06/some-post.en.md

If that is not the case, can you share where are files being saved?

Thanks, @erez, the {{fields.language}} tag helped create the file extensions with proper locale. I realize now that the files are saving in the correct directory, but it’s the filter setting that isn’t properly showing the files in each collection. If I remove the filter setting line, I’m able to see all of the files in the news folder from every subdirectory. If I keep the filter settings as follows:

filter: {field: "language", value: "en"}

then the collection shows No Entries.

All of my original posts didn’t have the language variable in their frontmatter, so I expected them to not show in the collection. However, when I created a new post within Netlify CMS and edited an existing post to include the language: en line in the frontmatter, they also didn’t show in the appropriate filtered collection.

The frontmatter of the newly created test post looks like this:

language: en
title: Test post
date: 2020-07-01T01:55:14.324Z

(I haven’t looked into the DateTime widget settings yet.)

The frontmatter of my edited existing post looks like this:

language: en
title: “Title of Post”
date: 2020-06-09T06:00:00-07:00

Hi @cptncrnch, that might be related to a pagination bug https://github.com/netlify/netlify-cms/issues/3950
How many entries do you have in the collection folder?
Can you try sorting the entries (that would force loading all entries)?

@erez, I have 22 entries. Sorting the entries does force load the entries and I’m able to see the two posts with the language: en line in its frontmatter.

Thanks @cptncrnch, that helps to confirm the issue.