build available theme list dynamically
This commit is contained in:
@ -83,6 +83,18 @@ def create_app():
|
||||
app.config['MAX_CONTENT_LENGTH'] = 1000 * 1000
|
||||
|
||||
os.makedirs(os.path.dirname(app.config["DB_PATH"]), exist_ok = True)
|
||||
|
||||
css_dir = 'data/static/css/'
|
||||
allowed_themes = []
|
||||
for f in os.listdir(css_dir):
|
||||
if not os.path.isfile(os.path.join(css_dir, f)):
|
||||
continue
|
||||
theme_name = os.path.splitext(os.path.basename(f))[0]
|
||||
allowed_themes.append(theme_name)
|
||||
|
||||
allowed_themes.sort(key=(lambda x: (x != 'style', x)))
|
||||
app.config['allowed_themes'] = allowed_themes
|
||||
|
||||
with app.app_context():
|
||||
from .schema import create as create_tables
|
||||
from .migrations import run_migrations
|
||||
@ -179,4 +191,11 @@ def create_app():
|
||||
def cachebust(subject):
|
||||
return f"{subject}?v={str(int(time.time()))}"
|
||||
|
||||
@app.template_filter('theme_name')
|
||||
def get_theme_name(subject: str):
|
||||
if subject == 'style':
|
||||
return 'Default'
|
||||
|
||||
return f'{subject.removeprefix('theme-').capitalize()} (beta)'
|
||||
|
||||
return app
|
||||
|
Reference in New Issue
Block a user