-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·72 lines (51 loc) · 1.57 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
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from flask import Flask, render_template
from flask_flatpages import FlatPages
from flask_frozen import Freezer
DEBUG = True
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
FREEZER_DESTINATION = 'output/build'
app = Flask(__name__)
app.config.from_object(__name__)
pages = FlatPages(app)
freezer = Freezer(app)
def _key(page):
n = page.meta['published'].toordinal()
if 'order' in page.meta:
n += int(page.meta['order'])
return n
def _posts(pages):
posts = (p for p in pages if 'published' in p.meta)
return sorted(posts, reverse=True, key=lambda p: _key(p))
@freezer.register_generator
def post():
posts = (p for p in pages if 'published' in p.meta)
for post in posts:
yield {'title': post['slug']}
@app.route('/')
def index():
posts = _posts(pages)
return render_template('index.html', post=posts[0], posts=posts[1:10])
@app.route('/post/<string:title>/')
def post(title):
post = pages.get_or_404(title)
return render_template('post.html', post=post)
@app.route('/arquivo/')
def arquivo():
return render_template('arquivo.html', posts=_posts(pages))
@app.route('/sobre/')
def sobre():
return render_template('sobre.html')
@app.route('/atom.xml/')
def atom_feed():
posts = _posts(pages)
return render_template('atom.xml', update_date=posts[0]['published'],
posts=posts)
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == 'build':
freezer.freeze()
else:
app.run(port=8000)