Finished implementation of configuration resolver

This commit is contained in:
Kevin Veen-Birkenbach 2025-01-09 14:20:59 +01:00
parent 8fb0cecfbe
commit c87c1df10a
4 changed files with 34 additions and 17 deletions

View File

@ -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"]:

View File

@ -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
@ -228,20 +226,19 @@ navigation:
icon:
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
href: https://www.facebook.com/kevinveenbirkenbach
subitems: []
- name: Communication
description: Social and developer networks
icon:
class: fa-brands fa-meta
href:
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

View File

@ -19,7 +19,11 @@
{% else %}
<li>
<a class="dropdown-item" href="{{ subitem.href }}" target="{{ subitem.target|default('_blank') }}" data-bs-toggle="tooltip" title="{{ subitem.description }}">
{% if subitem.icon is defined and subitem.icon.class is defined %}
<i class="{{ subitem.icon.class }}"></i> {{ subitem.name }}
{% else %}
<p>Fehlendes Icon im Subitem: {{ subitem }}</p>
{% endif %}
</a>
</li>
{% endif %}

View File

@ -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