Commit 3d408362 authored by Pietro Albini's avatar Pietro Albini

Merge branch 'random-changes' into develop

parents 28ede21f ebd841e0
Pipeline #89 running with stage
...@@ -39,6 +39,7 @@ setuptools.setup( ...@@ -39,6 +39,7 @@ setuptools.setup(
"pyyaml", "pyyaml",
"requests", "requests",
"toml", "toml",
"django-htmlmin",
], ],
packages = [ packages = [
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
<link rel="stylesheet" href="https://static.ubuntu-it.org/fonts/ubuntu/include.min.css"> <link rel="stylesheet" href="https://static.ubuntu-it.org/fonts/ubuntu/include.min.css">
<link rel="stylesheet" href="https://static.ubuntu-it.org/themes/italy/theme.min.css"> <link rel="stylesheet" href="https://static.ubuntu-it.org/themes/italy/theme.min.css">
<link rel="stylesheet" href="{{ url_for("static", filename="website.css") }}" /> <link rel="stylesheet" href="{{ url_for("static", filename="website.css") }}">
<link rel="shortcut icon" href="{{ url_for("static", filename="favicon.ico") }}">
{% block extra_header %}{% endblock %} {% block extra_header %}{% endblock %}
</head> </head>
......
...@@ -18,6 +18,7 @@ import datetime ...@@ -18,6 +18,7 @@ import datetime
import random import random
import string import string
from htmlmin.minify import html_minify
import gunicorn.app.base as baseapp import gunicorn.app.base as baseapp
...@@ -106,6 +107,22 @@ class ReverseProxied: ...@@ -106,6 +107,22 @@ class ReverseProxied:
def prepare_app(app): def prepare_app(app):
"""Add some utilities to the 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") @app.template_filter("format_timestamp")
def format_timestamp(timestamp): def format_timestamp(timestamp):
return datetime.datetime.fromtimestamp( 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