mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-07-04 10:13:10 +02:00
Solved caching bug
This commit is contained in:
parent
a0c7a7e8ca
commit
4d68ed2a24
44
app/app.py
44
app/app.py
@ -1,7 +1,5 @@
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
import requests
|
||||
import hashlib
|
||||
import yaml
|
||||
from utils.configuration_resolver import ConfigurationResolver
|
||||
from utils.cache_manager import CacheManager
|
||||
@ -14,39 +12,45 @@ cache_manager = CacheManager()
|
||||
cache_manager.clear_cache()
|
||||
|
||||
def load_config(app):
|
||||
"""Load and resolve the configuration."""
|
||||
"""Load and resolve the configuration from config.yaml."""
|
||||
with open("config.yaml", "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
# Resolve links in the configuration
|
||||
resolver = ConfigurationResolver(config)
|
||||
resolver.resolve_links()
|
||||
# Update the app configuration
|
||||
app.config.update(resolver.get_config())
|
||||
|
||||
app = Flask(__name__)
|
||||
load_config(app)
|
||||
|
||||
# Get the environment variable FLASK_ENV or set a default value
|
||||
FLASK_ENV = os.getenv("FLASK_ENV", "production")
|
||||
|
||||
@app.before_request
|
||||
def reload_config_in_dev():
|
||||
if FLASK_ENV == "development":
|
||||
load_config(app)
|
||||
|
||||
# Cache the icons
|
||||
def cache_icons_and_logos(app):
|
||||
"""Cache all icons and logos to local files."""
|
||||
for card in app.config["cards"]:
|
||||
# Just download the logo if an source url is passed
|
||||
if card["icon"].get("source"):
|
||||
card["icon"]["cache"] = cache_manager.cache_file(card["icon"]["source"])
|
||||
icon = card.get("icon", {})
|
||||
if icon.get("source"):
|
||||
icon["cache"] = cache_manager.cache_file(icon["source"])
|
||||
|
||||
app.config["company"]["logo"]["cache"] = cache_manager.cache_file(app.config["company"]["logo"]["source"])
|
||||
app.config["platform"]["favicon"]["cache"] = cache_manager.cache_file(app.config["platform"]["favicon"]["source"])
|
||||
app.config["platform"]["logo"]["cache"] = cache_manager.cache_file(app.config["platform"]["logo"]["source"])
|
||||
|
||||
# Get the environment variable FLASK_ENV or set a default value
|
||||
FLASK_ENV = os.getenv("FLASK_ENV", "production")
|
||||
|
||||
# Initialize Flask app
|
||||
app = Flask(__name__)
|
||||
|
||||
# Load configuration and cache assets on startup
|
||||
load_config(app)
|
||||
cache_icons_and_logos(app)
|
||||
|
||||
@app.before_request
|
||||
def reload_config_in_dev():
|
||||
"""Reload config and recache icons before each request in development mode."""
|
||||
if FLASK_ENV == "development":
|
||||
load_config(app)
|
||||
cache_icons_and_logos(app)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Render the main index page."""
|
||||
cards = app.config["cards"]
|
||||
lg_classes, md_classes = compute_card_classes(cards)
|
||||
return render_template(
|
||||
|
Loading…
x
Reference in New Issue
Block a user