You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from flask import Flask, render_template, request, abort, send_from_directory
  2. from dotenv import load_dotenv
  3. from markdown import markdown
  4. from glob import glob
  5. import json
  6. import os
  7. def preprocess_payload(payload):
  8. for column in payload.get('columns', []):
  9. md = column.get('markdown')
  10. if md:
  11. column['content'] = markdown(md)
  12. for slide in column.get('slides', []):
  13. md = slide.get('markdown')
  14. if md:
  15. slide['content'] = markdown(md)
  16. load_dotenv()
  17. payload = json.load(open("static/slides.json"))
  18. preprocess_payload(payload)
  19. application = Flask(__name__)
  20. @application.get("/")
  21. def home():
  22. return render_template("slides.html", **payload)
  23. @application.get("/choices/<topic>")
  24. def choices(topic):
  25. if topic in ["img", "bg"]:
  26. return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
  27. abort(404)
  28. @application.get("/schema.json")
  29. def schema():
  30. return render_template("slides.schema.json", backgrounds=choices("bg"))
  31. def home():
  32. return render_template("slides.html", **payload)
  33. @application.get("/editor")
  34. def editor():
  35. return render_template("editor.html")
  36. @application.route('/favicon.ico')
  37. def favicon():
  38. return send_from_directory(os.path.join(application.root_path, 'static'),
  39. 'favicon.ico', mimetype='image/vnd.microsoft.icon')