2022-09-23 11:35:56 -04:00
|
|
|
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)
|
2022-09-23 13:37:37 -04:00
|
|
|
with open(static_dir + 'styles_min.css', 'w') as minified_file:
|
|
|
|
minified_file.write(minified)
|