-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.py
61 lines (48 loc) · 1.43 KB
/
site.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
import sys
import os
from flask import Flask, abort, render_template, redirect
from flask_frozen import Freezer
from blog.flatpages import discover_pages, get_page
app = Flask(__name__)
freezer = Freezer(app)
discover_pages(app)
@app.route("/")
def index():
return render_template("index.html")
@freezer.register_generator
def pages():
for key in app.page_index.keys():
yield "page", {"path": key}
@app.route("/p/<path:path>/")
def page_with_prefix(path):
"""
Updated URL for pages. Previous URLS should perma-redirect to this scheme.
"""
full_path = app.page_index.get(path)
page = get_page(full_path)
if not page:
abort(404)
return render_template("page.html", page=page)
@app.route("/hfxbenches/")
def hfxbenches():
"""
Pointer to github.com/bartek/hfxbenches build
"""
return render_template("hfxbenches/index.html", token=os.environ.get('MAPBOX_TOKEN'))
@app.route("/hfxbikeparking/")
def hfxbikeparking():
"""
Pointer to github.com/bartek/hfxbikeparking build
"""
return render_template("hfxbikeparking/index.html", token=os.environ.get('MAPBOX_TOKEN'))
@app.route("/<path:path>/")
def page(path):
p = app.page_index.get(path)
if not p:
abort(404)
return redirect(f"/p/{path}", code=301)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "build":
freezer.freeze()
else:
app.run(port=4000, debug=True)