mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-07-04 18:23:09 +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
|
import os
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
import requests
|
|
||||||
import hashlib
|
|
||||||
import yaml
|
import yaml
|
||||||
from utils.configuration_resolver import ConfigurationResolver
|
from utils.configuration_resolver import ConfigurationResolver
|
||||||
from utils.cache_manager import CacheManager
|
from utils.cache_manager import CacheManager
|
||||||
@ -14,39 +12,45 @@ cache_manager = CacheManager()
|
|||||||
cache_manager.clear_cache()
|
cache_manager.clear_cache()
|
||||||
|
|
||||||
def load_config(app):
|
def load_config(app):
|
||||||
"""Load and resolve the configuration."""
|
"""Load and resolve the configuration from config.yaml."""
|
||||||
with open("config.yaml", "r") as f:
|
with open("config.yaml", "r") as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
# Resolve links in the configuration
|
|
||||||
resolver = ConfigurationResolver(config)
|
resolver = ConfigurationResolver(config)
|
||||||
resolver.resolve_links()
|
resolver.resolve_links()
|
||||||
# Update the app configuration
|
|
||||||
app.config.update(resolver.get_config())
|
app.config.update(resolver.get_config())
|
||||||
|
|
||||||
app = Flask(__name__)
|
def cache_icons_and_logos(app):
|
||||||
load_config(app)
|
"""Cache all icons and logos to local files."""
|
||||||
|
|
||||||
# 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
|
|
||||||
for card in app.config["cards"]:
|
for card in app.config["cards"]:
|
||||||
# Just download the logo if an source url is passed
|
icon = card.get("icon", {})
|
||||||
if card["icon"].get("source"):
|
if icon.get("source"):
|
||||||
card["icon"]["cache"] = cache_manager.cache_file(card["icon"]["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["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"]["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"])
|
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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
"""Render the main index page."""
|
||||||
cards = app.config["cards"]
|
cards = app.config["cards"]
|
||||||
lg_classes, md_classes = compute_card_classes(cards)
|
lg_classes, md_classes = compute_card_classes(cards)
|
||||||
return render_template(
|
return render_template(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user