from flask import Flask, render_template, request
from dotenv import load_dotenv
from markdown import markdown
import json

def preprocess_payload(payload):
    for column in payload.get('columns', []):
        md = column.get('markdown')
        if md:
            column['content'] = markdown(md)
        for slide in column.get('slides', []):
            md = slide.get('markdown')
            if md:
                slide['content'] = markdown(md)

load_dotenv()
payload = json.load(open("slides.json"))
preprocess_payload(payload)

application = Flask(__name__)

@application.get("/")
def home():
    return render_template("slides.html", **payload)

