From e77fc521bfdd4b75d7802f2e02ff2744f0fd245a Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 29 May 2024 18:57:32 +0200 Subject: [PATCH] feat: introduce dynamic SVG icon functionality Implemented a new template filter in Flask to dynamically render SVG icons, allowing for cleaner HTML templates and easier icon management. Added `coffee` and `envelope` SVG icons to the project's asset directory. This change not only streamlines the incorporation of new icons but also enhances the maintainability of the codebase by centralizing icon resources and reducing HTML clutter. Modified existing HTML templates to use this new dynamic icon rendering method, replacing hard-coded SVG and img tag icon implementations with the newly created template filter. This update significantly improves the way icons are handled throughout the application, providing a more scalable and efficient approach to managing and displaying graphical elements. --- assets/css/base.css | 4 ++++ assets/dist/icons/coffee.svg | 1 + assets/dist/icons/envelope.svg | 1 + main.py | 7 +++++++ templates/base.html | 16 +--------------- templates/index.html | 10 +++------- 6 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 assets/dist/icons/coffee.svg create mode 100644 assets/dist/icons/envelope.svg diff --git a/assets/css/base.css b/assets/css/base.css index 60880c9..0fa6901 100644 --- a/assets/css/base.css +++ b/assets/css/base.css @@ -119,6 +119,10 @@ h5 { color: #604c2e; } +.bs-icon.bs-icon-primary svg { + fill: var(--bs-primary-bg-subtle); +} + /* Responsive Styles */ @media (max-width: 768px) { .navbar .container { diff --git a/assets/dist/icons/coffee.svg b/assets/dist/icons/coffee.svg new file mode 100644 index 0000000..4d4e30a --- /dev/null +++ b/assets/dist/icons/coffee.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/dist/icons/envelope.svg b/assets/dist/icons/envelope.svg new file mode 100644 index 0000000..30b1cee --- /dev/null +++ b/assets/dist/icons/envelope.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/main.py b/main.py index dc49b56..9312623 100644 --- a/main.py +++ b/main.py @@ -81,6 +81,13 @@ if os.environ.get("PRIVATECOFFEE_DEV"): app.development_mode = True +def icon(icon_name): + file = send_from_directory("assets", f"dist/icons/{icon_name}.svg") + file_content = file.response.file.read().decode("utf-8") + return file_content + +app.add_template_filter(icon) + if __name__ == "__main__": parser = ArgumentParser(description="Run the private.coffee web server.") parser.add_argument("--port", type=int, default=9810) diff --git a/templates/base.html b/templates/base.html index 13593f7..2a5fa97 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,21 +75,7 @@
- - {{ "coffee" | icon | safe }}Private.coffee

diff --git a/templates/index.html b/templates/index.html index 94bf775..19c0522 100644 --- a/templates/index.html +++ b/templates/index.html @@ -30,7 +30,7 @@

- {% if service.icon %}{{ service.name }}{% endif %} + {% if service.icon %}{{ service.icon | icon | safe }}{% endif %}
{{ service.name }}

{{ service.long_description }}

@@ -91,9 +91,7 @@
-
- -
+
{{ "envelope" | icon | safe }}
Email

support@private.coffee

@@ -106,9 +104,7 @@
-
- -
+
{{ "matrix-logo" | icon | safe }}