From f8d1dac945e16a2f674619874ed963ba4b0867ca Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 23 Sep 2022 09:19:30 -0400 Subject: [PATCH 1/2] Break up css optimization functions. sans -> sans-serif --- flaskr/__init__.py | 26 ++++++++++++-------------- flaskr/static/styles.css | 9 +++------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/flaskr/__init__.py b/flaskr/__init__.py index 00c7092..521424d 100644 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -1,26 +1,27 @@ # Copyright Sage Vaillancourt 2021 import os - -from flask import ( - Flask, redirect, url_for, render_template, send_from_directory -) +from flask import Flask import writing INDEX = None -def optimize_css(): +def optimize_css(css: str) -> str: import re + minified_with_comments = "".join(list(map( + lambda line: re.sub(r'\s*([:{])\s*', '\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/flaskr/static/' css = open(static_dir + 'styles.css', 'r').read() - minified_with_comments = "".join(list(map( - lambda line: re.sub(r':\s*', ':', re.sub(r'^\s*', '', line)), - css.split('\n') - ))) - minified = re.sub(r'/\*[\s\S]*?\*/', "", minified_with_comments) + minified = optimize_css(css) minified_file = open(static_dir + 'styles_min.css', 'w') minified_file.write(minified) minified_file.close() @@ -40,10 +41,7 @@ def create_app(test_config=None): else: app.config.from_mapping(test_config) - try: - os.makedirs(app.instance_path) - except OSError: - pass + os.makedirs(app.instance_path, exist_ok=True) app.register_blueprint( writing.writing_blueprint, diff --git a/flaskr/static/styles.css b/flaskr/static/styles.css index 8696015..e1a498d 100644 --- a/flaskr/static/styles.css +++ b/flaskr/static/styles.css @@ -24,7 +24,7 @@ body { margin-right: auto; display: flex; flex-direction: column; - font-family: sans; + font-family: sans-serif; } h1, h2 { @@ -46,14 +46,11 @@ label { font-weight: bold; color: #eee; background-color: #757575; - padding-top: 0.15em; - padding-bottom: 0.15em; - padding-left: 0.5em; - padding-right: 0.5em; + padding: 0.15em 0.5em; } input, textarea { - font-family: sans; + font-family: sans-serif; } /* Small screens */ From 0eee7d0ef709363189f18cd8ffdd41e15cf5e614 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 23 Sep 2022 09:21:58 -0400 Subject: [PATCH 2/2] Fix optimization call. --- flaskr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flaskr/__init__.py b/flaskr/__init__.py index 521424d..a00cc28 100644 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -28,7 +28,7 @@ def optimize_css_file(): def create_app(test_config=None): - optimize_css() + optimize_css_file() app = Flask(__name__, instance_relative_config=True) app.config.from_mapping(