-
Notifications
You must be signed in to change notification settings - Fork 0
/
engelhard.py
64 lines (48 loc) · 1.73 KB
/
engelhard.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
from flask import Flask, render_template, Markup, render_template_string, url_for
from flask_flatpages import FlatPages, pygmented_markdown
# create the application
app = Flask(__name__)
pages = FlatPages(app)
# define a custom renderer to enable url_for in flatpages
def prerender_jinja(text):
prerendered_body = render_template_string(Markup(text))
return pygmented_markdown(prerendered_body)
APP_PREFIX = '/'
app.config.update(dict(
FREEZER_DESTINATION='build',
FREEZER_DESTINATION_IGNORE=['.GIT*', 'CNAME', '.gitignore', 'readme.md'],
FREEZER_BASE_URL='http://engelhard.georgetown.edu' + APP_PREFIX,
FREEZER_RELATIVE_URLS=False,
FLATPAGES_HTML_RENDERER=prerender_jinja,
))
profiles = []
stories = []
for p in pages:
if ('profiles' in p.path) and p.body:
profiles.append(p)
elif ('stories' in p.path) and p.body:
stories.append(p)
profiles = sorted(profiles, key=lambda k: (k.meta['faculty']))
stories = sorted(stories, key=lambda k: (k.meta['professor']))
# routes
@app.route('/')
def index():
return render_template('index.html')
@app.route('/profiles/')
def profile_list():
return render_template('profile_list.html', profiles=profiles)
@app.route('/stories/')
def faculty_stories():
return render_template('story_list.html', stories=stories)
@app.route('/<path:path>/')
def page(path):
pge = pages.get_or_404(path)
if 'profiles' in pge.path:
template = pge.meta.get('template', 'profile_detail.html')
elif 'stories' in pge.path:
template = pge.meta.get('template', 'story_detail.html')
else:
template = pge.meta.get('template', 'page.html')
return render_template(template, page=pge)
if __name__ == '__main__':
app.run(debug=True)