From 76a61f69e0b989314581b3cc4e4e8f52833509cc Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 23 Sep 2022 08:27:38 -0400 Subject: [PATCH] More precise CSS optimization. --- flaskr/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flaskr/__init__.py b/flaskr/__init__.py index 089524d..00c7092 100644 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -17,10 +17,10 @@ def optimize_css(): 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 or 'padding' in line or 'transition' in line else line.replace(' ', ''), + lambda line: re.sub(r':\s*', ':', re.sub(r'^\s*', '', line)), css.split('\n') ))) - minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments) + 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()