From 0c3600e9a0de6f404c03afb01f832682c9a64466 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 23 Mar 2023 14:38:30 +0200 Subject: [PATCH] preload banner url --- files/templates/default.html | 20 +++++++++++++++++++- files/templates/util/macros.html | 17 ----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/files/templates/default.html b/files/templates/default.html index 4397606ec9..e2c81d1c45 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -27,7 +27,25 @@ {% set expand = false %} {% endif %} {% endif %} - {{macros.banner(src, href, alt, expand, class)}} + + + {% if src %} + {% set banner_url = src %} + {% else %} + {% set path = "files/assets/images/" ~ SITE_NAME %} + + {%- if not v and os_path.exists(path ~ "/cached.webp") -%} + {% set banner_url = 'cached.webp' | asset_siteimg %} + {% elif os_path.exists(path ~ "/banners") -%} + {% set banner_url = macros.random_image("assets/images/" ~ SITE_NAME ~ "/banners") %} + {% else -%} + {% set banner_url = 'banner.webp' | asset_siteimg %} + {% endif %} + {% endif %} + + + {{alt|default('site banner')}} + {% endif %} {% endif %} {% endblock %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 319d74a03f..20d48a9f63 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -4,23 +4,6 @@ {%- endif -%} {%- endmacro -%} -{%- macro banner(src, href, alt, expand, class) %} - - {{alt|default('site banner')}} - -{% endmacro -%} - -{%- macro live_banner() -%} - {% set path = "files/assets/images/" ~ SITE_NAME %} - {%- if not v and os_path.exists(path ~ "/cached.webp") -%} - {{ 'cached.webp' | asset_siteimg -}} - {% elif os_path.exists(path ~ "/banners") -%} - {{ random_image("assets/images/" ~ SITE_NAME ~ "/banners") -}} - {% else -%} - {{ 'banner.webp' | asset_siteimg -}} - {% endif %} -{%- endmacro -%} - {%- macro random_image(path) -%} {{- "/" ~ path ~ "/" ~ listdir('files/' ~ path)|random() ~ '?x=1' }} {%- endmacro -%}