2021-07-23 17:30:15 -04:00
|
|
|
# Copyright Sage Vaillancourt 2021
|
|
|
|
|
|
|
|
import os
|
2022-09-23 09:19:30 -04:00
|
|
|
from flask import Flask
|
2021-07-23 17:30:15 -04:00
|
|
|
|
2021-07-23 23:09:08 -04:00
|
|
|
import writing
|
2021-07-23 17:30:15 -04:00
|
|
|
|
2021-07-31 23:14:59 -04:00
|
|
|
INDEX = None
|
|
|
|
|
2022-09-21 23:14:50 -04:00
|
|
|
|
2022-09-23 09:19:30 -04:00
|
|
|
def optimize_css(css: str) -> str:
|
2021-07-28 22:50:30 -04:00
|
|
|
import re
|
|
|
|
minified_with_comments = "".join(list(map(
|
2022-09-23 09:19:30 -04:00
|
|
|
lambda line: re.sub(r'\s*([:{])\s*', '\1', re.sub(r'^\s*', '', line)),
|
2021-07-28 22:50:30 -04:00
|
|
|
css.split('\n')
|
|
|
|
)))
|
2022-09-23 09:19:30 -04:00
|
|
|
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)
|
2021-07-28 22:50:30 -04:00
|
|
|
minified_file = open(static_dir + 'styles_min.css', 'w')
|
|
|
|
minified_file.write(minified)
|
|
|
|
minified_file.close()
|
|
|
|
|
2022-09-21 23:14:50 -04:00
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
def create_app(test_config=None):
|
2022-09-23 09:21:58 -04:00
|
|
|
optimize_css_file()
|
2021-07-28 22:50:30 -04:00
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
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)
|
|
|
|
|
2022-09-23 09:19:30 -04:00
|
|
|
os.makedirs(app.instance_path, exist_ok=True)
|
2021-07-23 17:30:15 -04:00
|
|
|
|
|
|
|
app.register_blueprint(
|
2021-07-23 23:09:08 -04:00
|
|
|
writing.writing_blueprint,
|
2022-09-21 23:14:50 -04:00
|
|
|
# url_prefix='/writing',
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return app
|