Files
lair.moe/blueprints/risdeveau/__init__.py
T

32 lines
832 B
Python

import os
from pathlib import Path
from htmlmin import minify
from flask import Blueprint, render_template, send_from_directory, send_file, abort
bp = Blueprint(
"risdeveau",
__name__,
subdomain="risdeveau",
template_folder="..",
static_folder=None
)
def render_tmpl(filename: str) -> str:
template_path = os.path.join("risdeveau/templates", filename)
return minify(
render_template(template_path),
remove_empty_space=True
)
@bp.route("/static/<path:filename>")
def static(filename: str):
static_folders = ("static", "../root/static")
for dir in static_folders:
if os.path.exists(path := os.path.join("blueprints/risdeveau", dir, filename)):
return send_file(path)
return abort(404)
@bp.route("/")
def index():
return render_tmpl('index.html')