Really get all pages and some cleanup
This commit is contained in:
@@ -5,7 +5,6 @@ from flask import Flask, render_template, request
|
||||
from flask_flatpages import FlatPages
|
||||
import arrow
|
||||
|
||||
|
||||
DEBUG = True
|
||||
FLATPAGES_AUTO_RELOAD = DEBUG
|
||||
FLATPAGES_EXTENSION = '.md'
|
||||
@@ -42,14 +41,15 @@ blogposts = sorted(blogposts, key=lambda p: p.meta['date'], reverse=True)
|
||||
|
||||
|
||||
|
||||
|
||||
# Permalinks
|
||||
@app.route("/")
|
||||
@app.route("/<path:path>")
|
||||
def permalink(path=''):
|
||||
def page(path=''):
|
||||
page = permalinks['/'+path]
|
||||
template = 'blog_post.html' if page in blogposts else 'page.html'
|
||||
return render_template(template, page=page)
|
||||
|
||||
# Blog listings
|
||||
@app.route("/blog/")
|
||||
@app.route("/blog/<string:tag>/")
|
||||
def blog_listing(tag=None):
|
||||
@@ -65,14 +65,26 @@ if __name__ == "__main__":
|
||||
from glob import iglob
|
||||
from shutil import move, rmtree
|
||||
freezer = Freezer(app)
|
||||
|
||||
# Make sure we get all pages
|
||||
@freezer.register_generator
|
||||
def page():
|
||||
yield from permalinks
|
||||
|
||||
# Freeze site
|
||||
freezer.freeze()
|
||||
|
||||
# Move static files
|
||||
for f in iglob('build/static/*'):
|
||||
move(f, 'build/'+f[len('build/static/'):])
|
||||
rmtree('build/static/')
|
||||
|
||||
else:
|
||||
# Serve static files too
|
||||
@app.route("/media/<path:path>")
|
||||
@app.route("/src/<path:path>")
|
||||
@app.route("/favicon.ico")
|
||||
def static_file(path):
|
||||
return app.send_static_file(request.path[1:])
|
||||
|
||||
app.run()
|
||||
|
||||
Reference in New Issue
Block a user