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(
packages = [
......@@ -18,6 +18,7 @@ import datetime
import random
import string
from htmlmin.minify import html_minify
import as baseapp
......@@ -106,6 +107,22 @@ class ReverseProxied:
def prepare_app(app):
"""Add some utilities to the app"""
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)
return response
def format_timestamp(timestamp):
return datetime.datetime.fromtimestamp(
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment