major update :O

This commit is contained in:
2026-01-18 23:21:44 +00:00
parent 53cd3852aa
commit 25b03aa105
28 changed files with 514 additions and 765 deletions

View File

@@ -0,0 +1,41 @@
# Imports
from flask import Blueprint, render_template, request, abort
from os import getenv as env
import logging, os, re
# Create blueprint
bp = Blueprint(
'dynamic_routes',
__name__,
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
static_folder=env('STATIC_FOLDER', default='../static')
)
# Create logger
log = logging.getLogger(__name__)
# Get all files in folder
def ListFiles(path):
files = []
for root, dirs, files_in_dir in os.walk(path):
for file in files_in_dir:
files.append(os.path.relpath(os.path.join(root, file), path))
for dir in dirs:
files.append(os.path.relpath(os.path.join(root, dir), path) + '/')
return files
# Catch-all route for generic pages
@bp.route('/<path:filename>')
def catch_all(filename):
try:
return render_template(f'pages/{filename if re.match(r'^.+\.[a-zA-Z0-9]+$', filename) else filename + '.html'}')
except Exception as e:
os_path = os.path.join(bp.template_folder, 'pages', filename)[3:]
print(os_path)
if os.path.isdir(os_path):
if not filename.endswith('/'): filename += '/'
return render_template('bases/directory.html', directory=filename, pages=ListFiles(os_path))
# If it is a file, return a 404 error
abort(404, f"Template '{filename}' not found: {e}")