123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- from flask import Flask, render_template, request, abort, send_from_directory
- from dotenv import load_dotenv
- from markdown import markdown
- from glob import glob
- import json
- import os
-
- 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("static/slides.json"))
- preprocess_payload(payload)
-
- application = Flask(__name__)
-
- @application.get("/")
- def home():
- return render_template("slides.html", **payload)
-
- @application.get("/choices/<topic>")
- def choices(topic):
- if topic in ["img", "bg"]:
- return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
- abort(404)
-
- @application.get("/schema.json")
- def schema():
- return render_template("slides.schema.json", backgrounds=choices("bg"))
-
- def home():
- return render_template("slides.html", **payload)
-
- @application.get("/editor")
- def editor():
- return render_template("editor.html")
-
- @application.route('/favicon.ico')
- def favicon():
- return send_from_directory(os.path.join(application.root_path, 'static'),
- 'favicon.ico', mimetype='image/vnd.microsoft.icon')
|