UnderCover/undercover/css.py

23 lines
619 B
Python

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)
minified_file = open(static_dir + 'styles_min.css', 'w')
minified_file.write(minified)
minified_file.close()