Mercurial > hg-website
annotate hgwebsite.py @ 474:68ea82e8ff7c
downloads: add link to PPA for ubuntu/debian
author | heatherboo <heather.j.booker@gmail.com> |
---|---|
date | Sat, 25 Feb 2017 12:36:03 -0800 |
parents | b173399d3635 |
children |
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__': | |
435
b173399d3635
thepage: update thepage site with more recent information
David Soria Parra <dsp@experimentalworks.net>
parents:
407
diff
changeset
|
36 app.run(host='0.0.0.0') |