-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
64 lines (44 loc) · 1.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Freeze Flask app into GitHub Pages
https://github.com/AshrithSagar/frozen-flask-gh-pages
"""
from os import path
from pathlib import Path
from flask import Flask, render_template, url_for
from flask_frozen import Freezer
template_folder = path.abspath("./wiki")
app = Flask(__name__, template_folder=template_folder)
# Enter your GitHub Pages URL here instead of frozen-flask-gh-pages
app.config["FREEZER_BASE_URL"] = "https:///2022-igem-wiki/"
# As configured in GitHub Pages Settings
app.config["FREEZER_DESTINATION"] = "docs"
app.config["FREEZER_RELATIVE_URLS"] = True
app.config["FREEZER_IGNORE_MIMETYPE_WARNINGS"] = True
app.config["FREEZER_DESTINATION_IGNORE"] = [
".nojekyll",
"static/assets/",
] # For GitHub Pages
freezer = Freezer(app)
@app.template_filter("link_url")
def link_url(endpoint, **values):
url = url_for(endpoint, **values)
if url.endswith("/index.html"):
url = url[:-10]
return url
@app.template_filter("static_dir")
def static_dir(filename):
return url_for("static", filename=filename)
@app.cli.command()
def freeze():
freezer.freeze()
@app.cli.command()
def serve():
freezer.run()
@app.route("/")
def index():
return render_template("pages/index.html")
@app.route("/<path:page>/")
def pages(page):
return render_template(str(Path("pages") / (page.lower() + ".html")))
if __name__ == "__main__":
app.run(port=8080, debug=True)