|
|
@ -1,11 +1,12 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
from flask import Flask, render_template, request, send_from_directory
|
|
|
|
|
|
|
|
from prefix import PrefixMiddleware
|
|
|
|
import yaml
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
from flask import Flask, render_template, request, send_from_directory
|
|
|
|
from markdown import markdown
|
|
|
|
from markdown import markdown
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from prefix import PrefixMiddleware
|
|
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
@ -15,47 +16,55 @@ PREFIX = os.environ.get("PREFIX", "")
|
|
|
|
REPO = os.environ.get("REPO", "https://git.xpub.nl/kamo/thesis.git")
|
|
|
|
REPO = os.environ.get("REPO", "https://git.xpub.nl/kamo/thesis.git")
|
|
|
|
SERVER_NAME = os.environ.get("SERVER_NAME", "localhost:3000")
|
|
|
|
SERVER_NAME = os.environ.get("SERVER_NAME", "localhost:3000")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pull():
|
|
|
|
def pull():
|
|
|
|
print('Retrieving contents')
|
|
|
|
print("Retrieving contents")
|
|
|
|
subprocess.call(['sh', 'update.sh', REPO])
|
|
|
|
subprocess.call(["sh", "update.sh", REPO])
|
|
|
|
|
|
|
|
|
|
|
|
def render():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open('index.yaml',"r") as i:
|
|
|
|
def render():
|
|
|
|
|
|
|
|
with open("index.yaml", "r") as i:
|
|
|
|
index = yaml.safe_load(i)
|
|
|
|
index = yaml.safe_load(i)
|
|
|
|
|
|
|
|
|
|
|
|
entries = []
|
|
|
|
entries = []
|
|
|
|
for entry in index:
|
|
|
|
for entry in index:
|
|
|
|
with open(os.path.join('contents', entry)) as e:
|
|
|
|
with open(os.path.join("contents", entry)) as e:
|
|
|
|
html = markdown(e.read(), extensions=[
|
|
|
|
html = markdown(
|
|
|
|
'markdown.extensions.attr_list',
|
|
|
|
e.read(),
|
|
|
|
'markdown.extensions.codehilite',
|
|
|
|
extensions=[
|
|
|
|
'markdown.extensions.fenced_code'
|
|
|
|
"markdown.extensions.attr_list",
|
|
|
|
])
|
|
|
|
"markdown.extensions.codehilite",
|
|
|
|
|
|
|
|
"markdown.extensions.fenced_code",
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
)
|
|
|
|
entries.append(html)
|
|
|
|
entries.append(html)
|
|
|
|
|
|
|
|
|
|
|
|
with open('index.html', 'w') as r:
|
|
|
|
with open("index.html", "w") as r:
|
|
|
|
r.write(render_template("render.html", contents=entries))
|
|
|
|
r.write(render_template("render.html", contents=entries))
|
|
|
|
|
|
|
|
|
|
|
|
return 'rendered'
|
|
|
|
return "rendered"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=PREFIX)
|
|
|
|
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=PREFIX)
|
|
|
|
app.config['SERVER_NAME'] = SERVER_NAME
|
|
|
|
app.config["SERVER_NAME"] = SERVER_NAME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pull();
|
|
|
|
pull()
|
|
|
|
with app.app_context():
|
|
|
|
with app.app_context():
|
|
|
|
render();
|
|
|
|
render()
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def home():
|
|
|
|
def home():
|
|
|
|
return send_from_directory(app.root_path, 'index.html')
|
|
|
|
return send_from_directory(app.root_path, "index.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/update', methods=['GET', 'POST'])
|
|
|
|
@app.route("/update", methods=["GET", "POST"])
|
|
|
|
def update():
|
|
|
|
def update():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == "POST":
|
|
|
|
pull();
|
|
|
|
pull()
|
|
|
|
return 'GET method not supported'
|
|
|
|
return "GET method not supported"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.run(port=PORT, debug=DEBUG)
|
|
|
|
app.run(port=PORT, debug=DEBUG)
|
|
|
|