54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
# Copyright Sage Vaillancourt 2021
|
|
|
|
import os
|
|
|
|
from flask import (
|
|
Flask, redirect, url_for, render_template, send_from_directory
|
|
)
|
|
|
|
import writing
|
|
|
|
INDEX = None
|
|
|
|
|
|
def optimize_css():
|
|
import re
|
|
root = os.path.dirname(os.getcwd())
|
|
static_dir = root + '/undercover/flaskr/static/'
|
|
css = open(static_dir + 'styles.css', 'r').read()
|
|
minified_with_comments = "".join(list(map(
|
|
lambda line: re.sub(r':\s*', ':', re.sub(r'^\s*', '', line)),
|
|
css.split('\n')
|
|
)))
|
|
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()
|
|
|
|
|
|
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)
|
|
|
|
try:
|
|
os.makedirs(app.instance_path)
|
|
except OSError:
|
|
pass
|
|
|
|
app.register_blueprint(
|
|
writing.writing_blueprint,
|
|
# url_prefix='/writing',
|
|
)
|
|
|
|
return app
|