Parse this article format (Pelican, Markdown)

I have a Pelican blog and I am attempting to use Netlify CMS with it. My article format looks like this:

title: My Article Title
slug: my-article-title
date: 2020-01-08
author: William

This is some *amazing* article content.

And my config.yml looks like this:

...

collections:
  - name: articles
    format: yaml-frontmatter
    frontmatter_delimiter: ''
    ...

Netlify CMS doesn’t parse any information from the existing files. Is there some combination of configuration options that will make this work? Or, do I have to have something besides an empty line to delimit my front matter?

Have a look at the (fairly old) Pelican starter at the Netlify Templates repo: https://github.com/netlify-templates/pelican-netlify-cms/. It uses format: markdown-python. It’s the first time that I come across that format option and I’m 99% sure it’s not documented, but it might just work.

I had not found that repo, so thanks for bringing it to my attention. Unfortunately, it looks like it is for https://github.com/netlify/netlify-cms-legacy. If I try format: markdown-python with the latest version of Netlify CMS I get:

Error loading the CMS configuration

Config Errors:

'collections[0].format' should be equal to one of the allowed values

Check your config.yml file.

Yeah, only noticed after I posted that comment that the repo uses v1. Would it be possible to add a frontmatter delimiter to your markdown files? I found a repo that does this (here), though I’m not sure how. I’ve never used pelican.

Thanks for you help. I probably won’t go back and update all my files to include delimiters right now, but I will always remember that as an option for the future.

For the benefit of anyone who finds this topic in the future, I just wrote a quick script to add delimiters to all my files:

import pathlib

path = pathlib.Path.cwd()

for item in path.iterdir():
    if item.suffix == '.md':
        new_lines = ['---\n']
        with item.open() as f:
            metadata_complete = False
            for line in f:
                if metadata_complete:
                    new_lines.append(line)
                else:
                    if line == '\n':
                        new_lines.append('---\n')
                        metadata_complete = True
                    else:
                        new_lines.append(line)
        with item.open('w') as f:
            f.writelines(new_lines)

This did not affect Pelican at all, and now Netlify CMS can parse the files, too.

2 Likes

thanks for sharing this, William! This will undeniably come up again.