From c87c1df10aa5b84ade5bb306c2f4fa51fc0dd45a Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 9 Jan 2025 14:20:59 +0100 Subject: [PATCH] Finished implementation of configuration resolver --- app/app.py | 17 ++++++++++++++--- app/config.yaml | 21 +++++++++------------ app/templates/moduls/navigation.html.j2 | 4 ++++ app/utils/configuration_resolver.py | 9 +++++++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/app.py b/app/app.py index ca4ada9..d563eee 100644 --- a/app/app.py +++ b/app/app.py @@ -3,6 +3,8 @@ from flask import Flask, render_template import requests import hashlib import yaml +from utils.configuration_resolver import ConfigurationResolver +from pprint import pprint # Verzeichnis mit Dateien, die gelöscht werden sollen TEMP_DIR = "static/cache/" @@ -30,7 +32,7 @@ def cache_file(file_url, cache_dir=TEMP_DIR): hash_object = hashlib.blake2s(file_url.encode('utf-8'), digest_size=8) hash_suffix = hash_object.hexdigest() - splitted_file_url = file_url.split("/"); + splitted_file_url = file_url.split("/") if splitted_file_url[-1] == "download": # Erstelle den Dateinamen mit Hash @@ -53,10 +55,16 @@ def cache_file(file_url, cache_dir=TEMP_DIR): return full_path def load_config(app): + """Load and resolve the configuration.""" # Lade die Konfigurationsdatei with open("config.yaml", "r") as f: config = yaml.safe_load(f) - app.config.update(config) + + # 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) @@ -68,6 +76,9 @@ FLASK_ENV = os.getenv("FLASK_ENV", "production") def reload_config_in_dev(): if FLASK_ENV == "development": load_config(app) + print("DEVELOPMENT ENVIRONMENT") + else: + print("PRODUCTIVE ENVIRONMENT") # Cachen der Icons for card in app.config["cards"]: @@ -81,4 +92,4 @@ def index(): return render_template("pages/index.html.j2", cards=app.config["cards"], company=app.config["company"], navigation=app.config["navigation"]) if __name__ == "__main__": - app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=5000) \ No newline at end of file + app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=5000) diff --git a/app/config.yaml b/app/config.yaml index b12ee8d..5b9caa1 100644 --- a/app/config.yaml +++ b/app/config.yaml @@ -204,13 +204,11 @@ navigation: class: fa-brands fa-telegram target: _blank href: https://t.me/kevinveenbirkenbach - subitems: [] - name: WhatsApp description: Chat with me on WhatsApp icon: class: fa-brands fa-whatsapp href: https://wa.me/491781798023 - subitems: [] footer: - name: External Accounts description: Me on other plattforms @@ -226,22 +224,21 @@ navigation: - name: Instagram description: Follow me on Instagram icon: - class: fa-brands fa-instagram + class: fa-brands fa-instagram href: https://www.instagram.com/kevinveenbirkenbach/ - subitems: [] - name: Facebook description: Like my Facebook page icon: - class: fa-brands fa-facebook + class: fa-brands fa-facebook href: https://www.facebook.com/kevinveenbirkenbach - subitems: [] - name: Communication description: Social and developer networks icon: class: fa-brands fa-meta - href: - subitems: + subitems: - link: navigation.header.contact.whatsapp + - link: navigation.header.contact.signal + - link: navigation.header.contact.telegram - name: Carreer Profiles icon: class: fa-solid fa-user-tie @@ -249,13 +246,13 @@ navigation: - name: XING description: Visit my XING profile icon: - class: bi bi-building + class: bi bi-building href: https://www.xing.com/profile/Kevin_VeenBirkenbach subitems: [] - name: LinkedIn description: Connect on LinkedIn icon: - class: bi bi-linkedin + class: bi bi-linkedin href: https://www.linkedin.com/in/kevinveenbirkenbach subitems: [] - name: Sports @@ -267,13 +264,13 @@ navigation: - name: Garmin description: My Garmin activities icon: - class: fa-solid fa-person-running + class: fa-solid fa-person-running href: https://s.veen.world/garmin subitems: [] - name: Eversports description: My Eversports sessions icon: - class: fa-solid fa-dumbbell + class: fa-solid fa-dumbbell href: https://s.veen.world/eversports subitems: [] - name: Duolingo diff --git a/app/templates/moduls/navigation.html.j2 b/app/templates/moduls/navigation.html.j2 index 12892df..768f048 100644 --- a/app/templates/moduls/navigation.html.j2 +++ b/app/templates/moduls/navigation.html.j2 @@ -19,7 +19,11 @@ {% else %}
  • + {% if subitem.icon is defined and subitem.icon.class is defined %} {{ subitem.name }} + {% else %} +

    Fehlendes Icon im Subitem: {{ subitem }}

    + {% endif %}
  • {% endif %} diff --git a/app/utils/configuration_resolver.py b/app/utils/configuration_resolver.py index db76240..a214351 100644 --- a/app/utils/configuration_resolver.py +++ b/app/utils/configuration_resolver.py @@ -49,7 +49,12 @@ class ConfigurationResolver: (item for item in current if isinstance(item, dict) and item.get("name", "").lower() == part), None ) - if found is None: + if found: + print( + f"Matching entry for '{part}' in list. Path so far: {' > '.join(parts[:parts.index(part)+1])}. " + f"Current list: {current}" + ) + else: raise ValueError( f"No matching entry for '{part}' in list. Path so far: {' > '.join(parts[:parts.index(part)+1])}. " f"Current list: {current}" @@ -71,7 +76,7 @@ class ConfigurationResolver: ) # Navigate into `subitems` if present - if isinstance(current, dict) and "subitems" in current: + if isinstance(current, dict) and ("subitems" in current and current["subitems"]): current = current["subitems"] return current