Trouble integrating Netlify CMS and Flask Frozen

Answering my own question…To get Netlify CMS and Flask-FlatPages and Flask-Frozen to play together you need to do the following:

  1. Do not put Flask-FlatPages into a Blueprint. This appears to be a known issue

  2. Set your build and pages directories to the root directory if you are following the application factory model

    app.config["FREEZER_DESTINATION"] = "../build"
    app.config["FLATPAGES_AUTO_RELOAD"] = True
    app.config["FLATPAGES_EXTENSION"] = ".md"
    app.config["FLATPAGES_ROOT"] = "../pages"
  1. Serve your Netlify CMS config.yml and index.html in a blueprint or as you like
admin_bp = Blueprint('admin_bp', __name__, template_folder='templates')

# Custom Views
@admin_bp.route('/config.yml')
def config():
    return render_template('config.yml')

@admin_bp.route('/')
def admin():
    return render_template('index.html')
  1. Create a /posts directory in your config.yml

folder: "posts"

  1. Shuttle newly created files from Netlify CMS to your Flask-FlatPages folder via freeze.py and modify the markdown, because otherwise you’ll get errors. See here.
import os
from flask_frozen import Freezer
from app import create_app

app = create_app()
freezer = Freezer(app)

if __name__ == '__main__':
    pages = os.listdir('pages')
    for post in os.listdir('posts'):
        if post not in pages:
            # Read in the file
            with open('{}/posts/{}'.format(os.getcwd(), post), 'r') as f:
                filedata = f.readlines()

                with open('{}/pages/{}'.format(os.getcwd(), post), 'w') as f:
                    for n, line in enumerate(filedata):
                        # Need to remove the first line if it's ---
                        if n == 0:
                            line = line.replace('---\n', '')
                        # All --- get replaced with empty spaces but we keep the \n
                        line = line.replace('---', '')
                        f.write(line)
    freezer.freeze()