Compare commits
2 commits
19ce49cc55
...
e5755066c3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e5755066c3 | ||
![]() |
2b6d94c766 |
3 changed files with 8 additions and 9 deletions
|
@ -3,4 +3,4 @@ from . import create_app
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run()
|
|
@ -9,7 +9,7 @@ def quote(value: str) -> str:
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
DEBUG = True
|
DEBUG = os.getenv('DEBUG', 'false').strip().lower() in ['true', '1', 'yes']
|
||||||
TESTING = False
|
TESTING = False
|
||||||
|
|
||||||
DB_BACKEND = os.getenv('DB_BACKEND', 'sqlite').lower()
|
DB_BACKEND = os.getenv('DB_BACKEND', 'sqlite').lower()
|
||||||
|
|
|
@ -6,7 +6,6 @@ from . import main
|
||||||
|
|
||||||
@main.after_request
|
@main.after_request
|
||||||
def prettify_or_minify_html_response(response):
|
def prettify_or_minify_html_response(response):
|
||||||
print(app.debug, response.content_type)
|
|
||||||
if response.content_type.startswith("text/html"):
|
if response.content_type.startswith("text/html"):
|
||||||
try:
|
try:
|
||||||
html = response.get_data(as_text=True)
|
html = response.get_data(as_text=True)
|
||||||
|
@ -15,13 +14,13 @@ def prettify_or_minify_html_response(response):
|
||||||
if app.debug:
|
if app.debug:
|
||||||
pretty_html = soup.prettify()
|
pretty_html = soup.prettify()
|
||||||
response.set_data(pretty_html.encode("utf-8")) # type: ignore
|
response.set_data(pretty_html.encode("utf-8")) # type: ignore
|
||||||
else:
|
#else:
|
||||||
# Minify by stripping extra whitespace between tags and inside text
|
# # Minify by stripping extra whitespace between tags and inside text
|
||||||
minified_html = re.sub(r">\s+<", "><", str(soup)) # collapse whitespace between tags
|
# minified_html = re.sub(r">\s+<", "><", str(soup)) # collapse whitespace between tags
|
||||||
minified_html = re.sub(r"\s{2,}", " ", minified_html) # collapse multi-spaces to one
|
# minified_html = re.sub(r"\s{2,}", " ", minified_html) # collapse multi-spaces to one
|
||||||
minified_html = re.sub(r"\n+", "", minified_html) # remove newlines
|
# minified_html = re.sub(r"\n+", "", minified_html) # remove newlines
|
||||||
|
|
||||||
response.set_data(minified_html.encode("utf-8")) # type: ignore
|
# response.set_data(minified_html.encode("utf-8")) # type: ignore
|
||||||
|
|
||||||
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue