more updates
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 2m59s
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 2m59s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Imports
|
||||
from flask import Blueprint, render_template, request, abort, send_from_directory
|
||||
from flask import Blueprint, render_template, request, abort, send_from_directory, send_file
|
||||
from os import getenv as env
|
||||
import logging
|
||||
|
||||
@@ -23,22 +23,31 @@ def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
# Route for robots.txt, sitemap.xml, and favicon.ico
|
||||
@bp.route('/robots.txt')
|
||||
@bp.route('/sitemap.xml')
|
||||
# Route for favicon
|
||||
@bp.route('/favicon.ico')
|
||||
def web_stuffs():
|
||||
return send_from_directory(
|
||||
env('STATIC_FOLDER', default='../static'),
|
||||
request.path.lstrip('/')
|
||||
)
|
||||
def favicon():
|
||||
return send_file('../static/content/other/favicon.ico')
|
||||
|
||||
|
||||
# catch-all route for any other static pages (only in root path)
|
||||
@bp.route('/<string:filename>')
|
||||
def static_files(filename):
|
||||
# Route for robots.txt
|
||||
@bp.route('/robots.txt')
|
||||
def robots():
|
||||
return send_file('../static/content/other/robots.txt')
|
||||
|
||||
|
||||
# Route for sitemap.xml
|
||||
@bp.route('/sitemap.xml')
|
||||
def sitemap():
|
||||
return send_file('../static/content/other/sitemap.xml')
|
||||
|
||||
|
||||
# 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(filename if filename.endswith('.html') else filename + '.html')
|
||||
return render_template(f'pages/{filename}')
|
||||
except Exception as e:
|
||||
log.error(f"Error serving static file {filename}: {e}")
|
||||
abort(404)
|
||||
abort(404, f"Template '{filename}' not found: {e}")
|
Reference in New Issue
Block a user