diff --git a/.gitignore b/.gitignore index 22cabc0..447e2be 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ temp/ .coverage htmlcov/ +*_min* + dist/ build/ *.egg-info/ diff --git a/flaskr/__init__.py b/flaskr/__init__.py index abfcf1a..17955fe 100644 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -1,17 +1,32 @@ # Copyright Sage Vaillancourt 2021 import os +import time +import subprocess from flask import ( Flask, redirect, url_for, render_template, send_from_directory ) -import subprocess -import time - import writing +def optimize_css(): + import re + root = os.path.dirname(os.getcwd()) + static_dir = root + '/undercover/flaskr/static/' + css = open(static_dir + 'styles.css', 'r').read() + minified_with_comments = "".join(list(map( + lambda line: line if 'media' in line else line.replace(' ', ''), + css.split('\n') + ))) + minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments) + minified_file = open(static_dir + 'styles_min.css', 'w') + minified_file.write(minified) + minified_file.close() + def create_app(test_config=None): + optimize_css() + app = Flask(__name__, instance_relative_config=True) app.config.from_mapping( SECRET_KEY='dev', diff --git a/flaskr/templates/writing.html b/flaskr/templates/writing.html index d315d7a..afb4b8c 100644 --- a/flaskr/templates/writing.html +++ b/flaskr/templates/writing.html @@ -1,8 +1,8 @@ - + + {{ url_for('static', filename='styles_min.css') }}">