Commit ebd841e0 authored by Pietro Albini's avatar Pietro Albini

Minify the output HTML

parent f5f65ae3
Pipeline #83 passed with stage
in 0 seconds
......@@ -39,6 +39,7 @@ setuptools.setup(
"pyyaml",
"requests",
"toml",
"django-htmlmin",
],
packages = [
......
......@@ -18,6 +18,7 @@ import datetime
import random
import string
from htmlmin.minify import html_minify
import gunicorn.app.base as baseapp
......@@ -106,6 +107,22 @@ class ReverseProxied:
def prepare_app(app):
"""Add some utilities to the app"""
@app.after_request
def after_request(response):
if "text/html" in response.content_type:
content = response.get_data(as_text=True)
# Minify the HTML
content = html_minify(content)
# Generate a random string and append it as the render ID
randstr = "".join(random.choice(string.ascii_letters) for _ in range(10))
content = "<!--render:%s-->%s" % (randstr, content)
response.set_data(content)
return response
@app.template_filter("format_timestamp")
def format_timestamp(timestamp):
return datetime.datetime.fromtimestamp(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment