diff options
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 52 |
1 files changed, 24 insertions, 28 deletions
@@ -7,12 +7,8 @@ from server import app # bit of a hack. # Brackets don't play nicely with Jinja so instead of using .format, # we just replace the special character $ -CONTENT_BLOCK = ( - "{% extends 'base.html' %}" - "{% block content %}" - "$" - "{% endblock %}" -) +CONTENT_BLOCK = "{% extends 'base.html' %}{% block content %}${% endblock %}" + def default_context(): """ @@ -21,8 +17,8 @@ def default_context(): make up the navbar """ return { - 'domain': app.config['DOMAIN'], - 'navbar': sorted(app.config['MAIN_SITE_DIRS']) + 'domain': app.config['DOMAIN'], + 'navbar': sorted(app.config['MAIN_SITE_DIRS']), } @@ -88,12 +84,7 @@ def home(): edit, though you can optionally change the title here if you wish """ context = default_context() - context.update( - { - 'title': app.config['HOME_TITLE'], - 'parent_dir': '/site/' - } - ) + context.update({'title': app.config['HOME_TITLE'], 'parent_dir': '/site/'}) return render_template("site/home.html", **context) @@ -115,14 +106,16 @@ def render_file(path): context.update( { 'title': path.split('.')[0].upper(), - 'parent_dir': '/site/' + '/'.join(path.split('/')[:-1]) + 'parent_dir': '/site/' + '/'.join(path.split('/')[:-1]), } ) if os.path.isfile(abs_path): if abs_path.endswith('.html'): with open(abs_path, 'rb') as f: content = f.read().decode("UTF-8") - return render_template_string(CONTENT_BLOCK.replace('$', content), **context) + return render_template_string( + CONTENT_BLOCK.replace('$', content), **context + ) elif abs_path.endswith('.html!'): return render_template("site/" + path, **context) else: @@ -131,9 +124,8 @@ def render_file(path): 'templates/site/', path, mimetype=siteconfig.MIMETYPES.get( - f".{ path.split('.')[-1] }", - siteconfig.DEFAULT_MIMETYPE - ) + f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE + ), ) elif os.path.isdir(abs_path): dirs, files, links, description = index_dir(abs_path) @@ -144,7 +136,7 @@ def render_file(path): 'dirs': dirs, 'files': files, 'links': links, - 'description': description + 'description': description, } ) return render_template("index.html", **context) @@ -160,10 +152,12 @@ def send_file_from_site(path): `render_file`, send the raw file to the user, when site is replace with path. """ - return send_from_directory('templates/site/', path, - mimetype=siteconfig.MIMETYPES.get( - f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE - ) + return send_from_directory( + 'templates/site/', + path, + mimetype=siteconfig.MIMETYPES.get( + f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE + ), ) @@ -173,8 +167,10 @@ def send_file_from_static(path): send_file - instead of rendering a file within a template as with `render_file`, send the raw file to the user """ - return send_from_directory('static/', path, - mimetype=siteconfig.MIMETYPES.get( - f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE - ) + return send_from_directory( + 'static/', + path, + mimetype=siteconfig.MIMETYPES.get( + f".{ path.split('.')[-1] }", siteconfig.DEFAULT_MIMETYPE + ), ) |