-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (38 loc) · 1.33 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
from flask import Flask, redirect, send_from_directory, url_for
from common import site_dir, build_dir, site_root
from render import render_template, get_doc
app = Flask(__name__)
@app.route('/')
def redirect_to_site_root():
return redirect(site_root)
@app.route(site_root)
def home():
return render_template('index.html')
@app.route(site_root + 'links/')
def links():
return render_template('doc.html', doc=get_doc('links/index.md'))
@app.route(site_root + 'lesson-<int:num>/')
def lesson(num):
md_file = 'lesson-{}/index.md'.format(num)
return render_template('lesson.html', doc=get_doc(md_file))
@app.route(site_root + 'lesson-<int:num>/slides/')
def slides(num):
md_file = 'lesson-{}/index.md'.format(num)
return render_template('slides.html', doc=get_doc(md_file))
@app.route(site_root + '<path:path>')
def static_files(path):
filepath = site_dir / path
if filepath.exists():
return send_from_directory(str(site_dir), path)
else:
return 'Page not found', 404
def get_build_urls():
"""
Return a sequence of URLs to generate HTML files from.
"""
with app.test_request_context():
for name in ('home', 'links'):
yield url_for(name)
for i in range(1, 5):
yield url_for('lesson', num=i)
yield url_for('slides', num=i)