2021-07-23 17:30:15 -04:00
|
|
|
# Copyright Sage Vaillancourt 2021
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from flask import (
|
|
|
|
Flask, redirect, url_for, render_template, send_from_directory
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
2021-07-28 22:50:30 -04:00
|
|
|
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: line if 'media' in line else line.replace(' ', ''),
|
|
|
|
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()
|
|
|
|
|
2022-09-21 23:14:50 -04:00
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
def create_app(test_config=None):
|
2021-07-28 22:50:30 -04:00
|
|
|
optimize_css()
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.makedirs(app.instance_path)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
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
|