UnderCover/flaskr/__init__.py

52 lines
1.2 KiB
Python
Raw Normal View History

# Copyright Sage Vaillancourt 2021
import os
from flask import Flask
2021-07-23 23:09:08 -04:00
import writing
INDEX = None
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 = optimize_css(css)
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',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
)
if test_config is None:
app.config.from_pyfile('config.py', silent=True)
else:
app.config.from_mapping(test_config)
os.makedirs(app.instance_path, exist_ok=True)
app.register_blueprint(
2021-07-23 23:09:08 -04:00
writing.writing_blueprint,
# url_prefix='/writing',
)
return app