This Gist contains a Flask app that emulates a MyST content server. We dynamically generate AST on the fly.
npm run theme:bookin MyST Theme repoflask --app app run --port 3100- Go!
 
| from flask import Flask, send_from_directory | |
| import json | |
| from itertools import cycle | |
| import datetime | |
| app = Flask(__name__) | |
| REAL_WORLD_DISCOVERIES = cycle( | |
| [ | |
| "birds-arent-real.json.template", | |
| "earth-is-flat.json.template", | |
| ] | |
| ) | |
| DOCUMENT = { | |
| "version": 2, | |
| "kind": "Article", | |
| "slug": "main", | |
| "location": "/main.md", | |
| "dependencies": [], | |
| "frontmatter": {}, | |
| "references": {"cite": {"order": [], "data": {}}}, | |
| } | |
| @app.route("/content/main.json") | |
| def send_page(): | |
| discovery_path = next(REAL_WORLD_DISCOVERIES) | |
| with open(discovery_path) as f: | |
| raw_data = f.read() | |
| data = json.loads(raw_data.format(datetime.datetime.now())) | |
| return {**DOCUMENT, "mdast": data} | |
| @app.route("/<path:path>") | |
| def send_rest(path): | |
| return send_from_directory(".", path) | 
| {{ | |
| "type": "root", | |
| "children": [ | |
| {{ | |
| "type": "block", | |
| "children": [ | |
| {{ | |
| "type": "heading", | |
| "depth": 1, | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "Birds aren’t real — {0:%I:%M %p} and {0:%S} seconds" | |
| }} | |
| ], | |
| "identifier": "birds-arent-real", | |
| "label": "Birds aren’t real", | |
| "html_id": "birds-arent-real", | |
| "implicit": true | |
| }}, | |
| {{ | |
| "type": "container", | |
| "kind": "quote", | |
| "children": [ | |
| {{ | |
| "type": "blockquote", | |
| "children": [ | |
| {{ | |
| "type": "paragraph", | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "THE GOVERNMENT KILLED ALL THE BIRDS AND REPLACED THEM WITH ROBOTS THAT SPY ON YOU" | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | |
| ], | |
| "class": "pull-quote" | |
| }}, | |
| {{ | |
| "type": "image", | |
| "url": "https://images.fineartamerica.com/images/artworkimages/mediumlarge/3/birds-arent-real-francois-ringuette.jpg", | |
| "height": "400px" | |
| }}, | |
| {{ | |
| "type": "paragraph", | |
| "children": [ | |
| {{ | |
| "type": "link", | |
| "url": "https://birdsarentreal.com/pages/evidence", | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "See the evidence" | |
| }} | |
| ], | |
| "class": "button", | |
| "urlSource": "https://birdsarentreal.com/pages/evidence" | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | 
| {"version":2,"myst":"1.6.3","options":{},"nav":[],"actions":[],"projects":[{"id":"cd2f6ab6-f214-4f9b-9c77-848357bc9000","exports":[],"bibliography":[],"title":"main","index":"main","pages":[]}]} | 
| {{ | |
| "type": "root", | |
| "children": [ | |
| {{ | |
| "type": "block", | |
| "children": [ | |
| {{ | |
| "type": "heading", | |
| "depth": 1, | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "Oblate spheroids are a LIE — {0:%I:%M %p} and {0:%S} seconds" | |
| }} | |
| ], | |
| "identifier": "oblate-spheroids-are-a-lie", | |
| "label": "Oblate spheroids are a LIE", | |
| "html_id": "oblate-spheroids-are-a-lie", | |
| "implicit": true | |
| }}, | |
| {{ | |
| "type": "container", | |
| "kind": "quote", | |
| "children": [ | |
| {{ | |
| "type": "blockquote", | |
| "children": [ | |
| {{ | |
| "type": "paragraph", | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "The earth is flat, has always been flat, and that’s that — FACT." | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | |
| ], | |
| "class": "pull-quote" | |
| }}, | |
| {{ | |
| "type": "image", | |
| "url": "https://tse1.mm.bing.net/th/id/OIP.Pp3_DjA_8ofNIWQiwVzSAAHaGi?pid=Api", | |
| "height": "400px" | |
| }}, | |
| {{ | |
| "type": "paragraph", | |
| "children": [ | |
| {{ | |
| "type": "link", | |
| "url": "https://en.wikipedia.org/wiki/Flat_Earth", | |
| "children": [ | |
| {{ | |
| "type": "text", | |
| "value": "See the evidence" | |
| }} | |
| ], | |
| "class": "button", | |
| "urlSource": "https://en.wikipedia.org/wiki/Flat_Earth", | |
| "data": {{ | |
| "page": "Flat_Earth", | |
| "wiki": "https://en.wikipedia.org/", | |
| "lang": "en" | |
| }}, | |
| "internal": false, | |
| "protocol": "wiki" | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | |
| ] | |
| }} | 
| {"version":"1","myst":"1.6.3","references":[{"kind":"page","data":"/content/main.json","url":"/"}]} | 
| flask |