-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
84 lines (66 loc) · 1.94 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
from flask import Flask, render_template
from flask_frozen import Freezer
from htmlmin.minify import html_minify
from flask_sitemap import Sitemap
import sys
app = Flask(__name__)
app.config.update(
DEBUG=True,
FREEZER_RELATIVE_URLS=True,
SITEMAP_INCLUDE_RULES_WITHOUT_PARAMS=True,
)
ext = Sitemap(app=app)
freezer = Freezer(app)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.route('/404.html')
def static_404():
return render_template('404.html')
@app.route("/")
def index():
return render_template('index.html')
@app.route("/about.html")
def about():
return render_template('about.html')
@app.route("/products.html")
def products():
return render_template('products.html')
@app.route("/contact.html")
def contact():
return render_template('contact.html')
@app.route("/thanks.html")
def thanks():
return render_template('thanks.html')
@app.route("/pedagogie.html")
def pedagogie():
return render_template('pedagogie.html')
@app.route("/legal.html")
def legal():
return render_template('legal.html')
@app.route("/robots.txt")
def robots():
return render_template('robots.txt')
@app.context_processor
def utility_processor():
def app_url(app):
return u'https://{}.polylearn.co'.format(app)
return dict(app_url=app_url)
@app.after_request
def response_minify(response):
"""
minify html response to decrease site traffic
"""
if (response.content_type == u'text/html; charset=utf-8'):
response.direct_passthrough = False
response.data = html_minify(response.data)
return response
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == "build":
freezer.freeze()
with open("build/sitemap.xml") as f:
sitemap = f.read()
with open("build/sitemap.xml", "w") as f:
f.write(sitemap.replace("http://localhost/", "https://polylearn.co/"))
else:
app.run()