mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-01-15 19:23:58 +01:00
Finished implementation of configuration resolver
This commit is contained in:
parent
8fb0cecfbe
commit
c87c1df10a
15
app/app.py
15
app/app.py
@ -3,6 +3,8 @@ from flask import Flask, render_template
|
|||||||
import requests
|
import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import yaml
|
import yaml
|
||||||
|
from utils.configuration_resolver import ConfigurationResolver
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
# Verzeichnis mit Dateien, die gelöscht werden sollen
|
# Verzeichnis mit Dateien, die gelöscht werden sollen
|
||||||
TEMP_DIR = "static/cache/"
|
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_object = hashlib.blake2s(file_url.encode('utf-8'), digest_size=8)
|
||||||
hash_suffix = hash_object.hexdigest()
|
hash_suffix = hash_object.hexdigest()
|
||||||
|
|
||||||
splitted_file_url = file_url.split("/");
|
splitted_file_url = file_url.split("/")
|
||||||
|
|
||||||
if splitted_file_url[-1] == "download":
|
if splitted_file_url[-1] == "download":
|
||||||
# Erstelle den Dateinamen mit Hash
|
# Erstelle den Dateinamen mit Hash
|
||||||
@ -53,10 +55,16 @@ def cache_file(file_url, cache_dir=TEMP_DIR):
|
|||||||
return full_path
|
return full_path
|
||||||
|
|
||||||
def load_config(app):
|
def load_config(app):
|
||||||
|
"""Load and resolve the configuration."""
|
||||||
# Lade die Konfigurationsdatei
|
# Lade die Konfigurationsdatei
|
||||||
with open("config.yaml", "r") as f:
|
with open("config.yaml", "r") as f:
|
||||||
config = yaml.safe_load(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__)
|
app = Flask(__name__)
|
||||||
load_config(app)
|
load_config(app)
|
||||||
@ -68,6 +76,9 @@ FLASK_ENV = os.getenv("FLASK_ENV", "production")
|
|||||||
def reload_config_in_dev():
|
def reload_config_in_dev():
|
||||||
if FLASK_ENV == "development":
|
if FLASK_ENV == "development":
|
||||||
load_config(app)
|
load_config(app)
|
||||||
|
print("DEVELOPMENT ENVIRONMENT")
|
||||||
|
else:
|
||||||
|
print("PRODUCTIVE ENVIRONMENT")
|
||||||
|
|
||||||
# Cachen der Icons
|
# Cachen der Icons
|
||||||
for card in app.config["cards"]:
|
for card in app.config["cards"]:
|
||||||
|
@ -204,13 +204,11 @@ navigation:
|
|||||||
class: fa-brands fa-telegram
|
class: fa-brands fa-telegram
|
||||||
target: _blank
|
target: _blank
|
||||||
href: https://t.me/kevinveenbirkenbach
|
href: https://t.me/kevinveenbirkenbach
|
||||||
subitems: []
|
|
||||||
- name: WhatsApp
|
- name: WhatsApp
|
||||||
description: Chat with me on WhatsApp
|
description: Chat with me on WhatsApp
|
||||||
icon:
|
icon:
|
||||||
class: fa-brands fa-whatsapp
|
class: fa-brands fa-whatsapp
|
||||||
href: https://wa.me/491781798023
|
href: https://wa.me/491781798023
|
||||||
subitems: []
|
|
||||||
footer:
|
footer:
|
||||||
- name: External Accounts
|
- name: External Accounts
|
||||||
description: Me on other plattforms
|
description: Me on other plattforms
|
||||||
@ -228,20 +226,19 @@ navigation:
|
|||||||
icon:
|
icon:
|
||||||
class: fa-brands fa-instagram
|
class: fa-brands fa-instagram
|
||||||
href: https://www.instagram.com/kevinveenbirkenbach/
|
href: https://www.instagram.com/kevinveenbirkenbach/
|
||||||
subitems: []
|
|
||||||
- name: Facebook
|
- name: Facebook
|
||||||
description: Like my Facebook page
|
description: Like my Facebook page
|
||||||
icon:
|
icon:
|
||||||
class: fa-brands fa-facebook
|
class: fa-brands fa-facebook
|
||||||
href: https://www.facebook.com/kevinveenbirkenbach
|
href: https://www.facebook.com/kevinveenbirkenbach
|
||||||
subitems: []
|
|
||||||
- name: Communication
|
- name: Communication
|
||||||
description: Social and developer networks
|
description: Social and developer networks
|
||||||
icon:
|
icon:
|
||||||
class: fa-brands fa-meta
|
class: fa-brands fa-meta
|
||||||
href:
|
|
||||||
subitems:
|
subitems:
|
||||||
- link: navigation.header.contact.whatsapp
|
- link: navigation.header.contact.whatsapp
|
||||||
|
- link: navigation.header.contact.signal
|
||||||
|
- link: navigation.header.contact.telegram
|
||||||
- name: Carreer Profiles
|
- name: Carreer Profiles
|
||||||
icon:
|
icon:
|
||||||
class: fa-solid fa-user-tie
|
class: fa-solid fa-user-tie
|
||||||
|
@ -19,7 +19,11 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item" href="{{ subitem.href }}" target="{{ subitem.target|default('_blank') }}" data-bs-toggle="tooltip" title="{{ subitem.description }}">
|
<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 }}
|
<i class="{{ subitem.icon.class }}"></i> {{ subitem.name }}
|
||||||
|
{% else %}
|
||||||
|
<p>Fehlendes Icon im Subitem: {{ subitem }}</p>
|
||||||
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -49,7 +49,12 @@ class ConfigurationResolver:
|
|||||||
(item for item in current if isinstance(item, dict) and item.get("name", "").lower() == part),
|
(item for item in current if isinstance(item, dict) and item.get("name", "").lower() == part),
|
||||||
None
|
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(
|
raise ValueError(
|
||||||
f"No matching entry for '{part}' in list. Path so far: {' > '.join(parts[:parts.index(part)+1])}. "
|
f"No matching entry for '{part}' in list. Path so far: {' > '.join(parts[:parts.index(part)+1])}. "
|
||||||
f"Current list: {current}"
|
f"Current list: {current}"
|
||||||
@ -71,7 +76,7 @@ class ConfigurationResolver:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Navigate into `subitems` if present
|
# 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"]
|
current = current["subitems"]
|
||||||
|
|
||||||
return current
|
return current
|
||||||
|
Loading…
Reference in New Issue
Block a user