-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·70 lines (50 loc) · 1.66 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
65
66
67
68
69
70
#!/usr/bin/env python
import codecs
import json
import argparse
from flask import Flask, Markup, render_template
import markdown
from smartypants import smartypants
import app_config
from render_utils import make_context, smarty_filter, urlencode_filter
import static
app = Flask(__name__)
app.jinja_env.filters['smarty'] = smarty_filter
app.jinja_env.filters['urlencode'] = urlencode_filter
# Example application views
@app.route('/')
def index():
context = make_context()
with open('data/featured.json') as f:
context['featured'] = json.load(f)
return render_template('index.html', **context)
@app.route('/about')
def about():
context = make_context()
f = codecs.open("posts/intro.md", mode="r", encoding="utf-8")
contents = f.read()
html = markdown.markdown(smartypants(contents))
context['markdown'] = Markup(html)
return render_template('post.html', **context)
@app.route('/posts/<string:slug>')
def _post(slug):
context = make_context()
index = context['COPY']['index']
for row in index:
if slug == row['slug']:
context['post_data'] = row
f = codecs.open("posts/%s.md" % slug, mode="r", encoding="utf-8")
contents = f.read()
html = markdown.markdown(contents)
context['markdown'] = Markup(html)
return render_template('post.html', **context)
app.register_blueprint(static.static)
# Boilerplate
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port')
args = parser.parse_args()
server_port = 8000
if args.port:
server_port = int(args.port)
app.run(host='0.0.0.0', port=server_port, debug=app_config.DEBUG)