Merge branch 'main' of https://gitlab.com/sagev9000/undercover
This commit is contained in:
commit
f1090abbc4
|
@ -2,8 +2,9 @@ bcrypt==4.0.0
|
|||
click==8.1.3
|
||||
email-validator==1.3.0
|
||||
Flask==2.2.2
|
||||
Flask-WTF==1.0.1
|
||||
Flask-Minify==0.39
|
||||
Flask-SQLAlchemy==2.5.1
|
||||
Flask-WTF==1.0.1
|
||||
gunicorn==20.1.0
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.2
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
from undercover import css
|
||||
|
||||
|
||||
def test_empty_string():
|
||||
assert css.optimize_css("") == ""
|
||||
|
||||
|
||||
def test_simple_definition():
|
||||
simple_definition = """
|
||||
div {
|
||||
width: 100%;
|
||||
}
|
||||
"""
|
||||
assert css.optimize_css(simple_definition) == "div{width:100%;}"
|
||||
|
||||
|
||||
def test_multi_part_property():
|
||||
simple_definition = """
|
||||
div {
|
||||
padding: 1em 2em 3em 4em;
|
||||
}
|
||||
"""
|
||||
assert css.optimize_css(simple_definition) == "div{padding:1em 2em 3em 4em;}"
|
|
@ -4,15 +4,14 @@ import os
|
|||
import sys
|
||||
|
||||
from flask import Flask
|
||||
from flask_minify import Minify
|
||||
|
||||
import undercover.routes
|
||||
from undercover.css import optimize_css_file
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
optimize_css_file()
|
||||
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
Minify(app=app, html=True, js=True, cssless=True)
|
||||
secret_key = os.environ.get('UNDERCOVER_SECRET_KEY')
|
||||
if not secret_key:
|
||||
sys.stderr.write("WARNING: UNDERCOVER_SECRET_KEY is not defined! Application may be insecure.\n")
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import os
|
||||
|
||||
|
||||
def optimize_css(css: str) -> str:
|
||||
import re
|
||||
minified_with_comments = "".join(list(map(
|
||||
lambda line: re.sub(r'\s*([:{])\s*', r'\1', re.sub(r'^\s*', '', line)),
|
||||
css.split('\n')
|
||||
)))
|
||||
return re.sub(r'/\*[\s\S]*?\*/', "", minified_with_comments)
|
||||
|
||||
|
||||
def optimize_css_file():
|
||||
root = os.path.dirname(os.getcwd())
|
||||
static_dir = root + '/undercover/undercover/static/'
|
||||
css = open(static_dir + 'styles.css', 'r').read()
|
||||
minified = optimize_css(css)
|
||||
with open(static_dir + 'styles_min.css', 'w') as minified_file:
|
||||
minified_file.write(minified)
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<head>
|
||||
<title>{% block title %}UnderCover{% endblock title %}</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles_min.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
|
||||
<link rel="icon" href="{{ url_for('static', filename='favicon.png') }}" />
|
||||
<meta name="viewport" content="user-scalable=no; width=device-width">
|
||||
{% block head %}{{ head }}{% endblock head %}
|
||||
|
|
Loading…
Reference in New Issue