-
Notifications
You must be signed in to change notification settings - Fork 1
/
website.py
58 lines (43 loc) · 1.2 KB
/
website.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
#!/usr/bin/python
"""
The site entry point.
"""
import yaml
import argparse
from flask import Flask, render_template, request
from flask_flatpages import FlatPages
from flask_frozen import Freezer
DEBUG=True
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
app = Flask(__name__)
app.config.from_object(__name__)
pages = FlatPages(app)
freezer = Freezer(app)
def get_pages(page_type, order_by=None):
"""
Get all the pages of the given type, eventually ordered by the specified criteria.
"""
if order_by is not None:
page_list = sorted(pages, key=lambda p: p.meta.get(order_by, 0))
else:
page_list = pages
return [page for page in page_list if page.meta.get('type') == page_type]
@app.route('/')
def index():
return render_template(
'index.j2',
)
def main():
"""
The script entry point.
"""
parser = argparse.ArgumentParser(description='Website generator.')
parser.add_argument('--freeze', '-f', action='store_true', help='Freezes the website instead of running it.')
args = parser.parse_args()
if args.freeze:
freezer.freeze()
else:
app.run(port=5000, host='0.0.0.0')
if __name__ == '__main__':
main()