This commit is contained in:
2025-08-07 21:25:10 +01:00
parent a0562330a3
commit 66806ad922
17 changed files with 192 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
# Imports
from flask import Blueprint, render_template, request, abort, send_from_directory, send_file
from flask import Blueprint, render_template, request, abort, send_file
from os import getenv as env
import logging
import logging, os
# Create blueprint
@@ -44,10 +44,22 @@ def sitemap():
# Catch-all route for generic pages
@bp.route('/<path:filename>')
def catch_all(filename):
# try to find template in the pages directory and add .html extension
if not filename.endswith('.html'):
filename += '.html'
try:
return render_template(f'pages/{filename}')
try: return render_template(f'pages/{filename if filename.endswith(".html") else filename + ".html"}')
except Exception as e:
# If the template is not found, check if it is a directory
os_path = os.path.join(bp.template_folder, 'pages', filename)[3:]
if os.path.isdir(os_path):
# walk through the directory and find all files
pages = []
for root, dirs, files_in_dir in os.walk(os_path):
for file in files_in_dir:
pages.append(os.path.relpath(os.path.join(root, file), os_path))
for dir in dirs:
pages.append(os.path.relpath(os.path.join(root, dir), os_path) + '/')
# If it is a directory, render a directory page
if not filename.endswith('/'): filename += '/'
return render_template('bases/directory.html', directory=filename, pages=pages)
# If it is a file, return a 404 error
abort(404, f"Template '{filename}' not found: {e}")