Mercurial > hg-website
annotate hgwebsite.py @ 408:595c6707635f
Serve our font directly
author | David Soria Parra <davidsp@fb.com> |
---|---|
date | Tue, 11 Mar 2014 15:41:25 -0700 |
parents | 8e93934dc587 |
children | b173399d3635 |
rev | line source |
---|---|
400 | 1 # |
2 # (c) 2014 David Soria Parra <dsp@php.net> | |
3 # | |
4 # This software may be used and distributed according to the terms of the | |
5 # GNU General Public License version 2 or any later version. | |
6 import os | |
7 import flask | |
8 | |
407
8e93934dc587
Route static url directly
David Soria Parra <davidsp@fb.com>
parents:
405
diff
changeset
|
9 app = flask.Flask(__name__, static_url_path='') |
400 | 10 |
11 | |
12 @app.route('/') | |
13 def indexpage(): | |
14 return flask.render_template('frontpage.html') | |
15 | |
16 | |
17 @app.route('/<site>') | |
18 def about(site=None): | |
19 if not site: | |
20 flask.abort(404) | |
401 | 21 root = os.path.dirname(os.path.abspath(__file__)) |
22 tpath = os.path.join(root, 'templates', site, 'index.html') | |
405
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
23 if os.path.exists(tpath): |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
24 t = os.path.join(site, 'index.html') |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
25 return flask.render_template(t) |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
26 spath = os.path.join(root, 'static', site) |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
27 if os.path.exists(spath): |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
28 return app.send_static_file(site) |
4dfad479ee98
Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents:
401
diff
changeset
|
29 flask.abort(404) |
400 | 30 |
31 | |
32 if os.getenv("HGWEBSITE_DEBUG", None): | |
33 app.debug = True | |
34 | |
35 if __name__ == '__main__': | |
36 app.run() |