From 1c3db86b75d0bb4074a75d212a6e0f3b3f56dc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar?= Date: Sat, 26 Aug 2023 01:57:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat(image=20shortcodes):=20add=20lazy?= =?UTF-8?q?=20loading=20(#116)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additionally sets the `alt` parameters as optional and cleans HTML output. --- content/blog/shortcodes.ca.md | 4 +++- content/blog/shortcodes.es.md | 6 ++++-- content/blog/shortcodes.md | 4 +++- templates/shortcodes/dimmable_image.html | 6 ++++-- templates/shortcodes/dual_theme_image.html | 14 ++++++++------ templates/shortcodes/full_width_image.html | 6 ++++-- templates/shortcodes/image_hover.html | 9 ++++----- templates/shortcodes/image_toggler.html | 12 +++++------- templates/shortcodes/invertible_image.html | 10 ++++++---- 9 files changed, 41 insertions(+), 30 deletions(-) diff --git a/content/blog/shortcodes.ca.md b/content/blog/shortcodes.ca.md index 7a9daa94f..14f5de8e3 100644 --- a/content/blog/shortcodes.ca.md +++ b/content/blog/shortcodes.ca.md @@ -1,7 +1,7 @@ +++ title = "Shortcodes personalitzats" date = 2023-02-19 -updated = 2023-08-24 +updated = 2023-08-26 description = "Aquest tema inclou alguns shortcodes personalitzats útils que pots utilitzar per millorar les teves publicacions. Ja sigui per mostrar imatges que s'adapten als temes clar i fosc, o per donar format a una secció de referències amb un aspecte professional, aquests shortcodes personalitzats t'ajudaran." [taxonomies] @@ -15,6 +15,8 @@ quick_navigation_buttons = true ## Shortcodes d'imatge +**Nota**: tots els shortcodes d'imatge tenen dos paràmetres opcionals: `full_width`, que té com a valor predeterminat `false` (vegeu [a sota](#imatge-d-amplada-completa)), i `lazy_loading`, que té com a valor predeterminat `true`. + ### Imatges per a temes duals Útil si vols utilitzar una imatge diferent pels temes clar i fosc: diff --git a/content/blog/shortcodes.es.md b/content/blog/shortcodes.es.md index 8ab4ab3cf..67e2b0043 100644 --- a/content/blog/shortcodes.es.md +++ b/content/blog/shortcodes.es.md @@ -1,7 +1,7 @@ +++ title = "Shortcodes personalizados" date = 2023-02-19 -updated = 2023-08-24 +updated = 2023-08-26 description = "Este tema incluye algunos shortcodes personalizados útiles que puedes utilizar para mejorar tus publicaciones. Puedes mostrar imágenes que se adapten a los temas claro y oscuro, dar formato a una sección de referencias con un aspecto profesional, y más." [taxonomies] @@ -13,7 +13,9 @@ toc_levels = 2 quick_navigation_buttons = true +++ -## Shortcodes de imágenes +## Shortcodes de imagen + +**Nota**: todos los shortcodes de imagen tienen dos parámetros opcionales: `full_width`, que tiene como valor predeterminado `false` (ver [más abajo](#imagen-a-ancho-completo)), y `lazy_loading`, que tiene como valor predeterminado `true`. ### Imágenes de doble tema diff --git a/content/blog/shortcodes.md b/content/blog/shortcodes.md index f26d6b0b3..1564e9d0f 100644 --- a/content/blog/shortcodes.md +++ b/content/blog/shortcodes.md @@ -1,7 +1,7 @@ +++ title = "Custom shortcodes" date = 2023-02-19 -updated = 2023-08-24 +updated = 2023-08-26 description = "This theme includes some useful custom shortcodes that you can use to enhance your posts. Whether you want to display images that adapt to light and dark themes, or format a professional-looking reference section, these custom shortcodes have got you covered." [taxonomies] @@ -15,6 +15,8 @@ quick_navigation_buttons = true ## Image shortcodes +**Note**: all image shortcodes have two optional parameters: `full_width`, which defaults to `false` (see [below](#full-width-image)), and `lazy_loading`, which defaults to `true`. + ### Dual theme images Useful if you want to use a different image for the light and dark themes: diff --git a/templates/shortcodes/dimmable_image.html b/templates/shortcodes/dimmable_image.html index 84da02918..2106f7eb6 100644 --- a/templates/shortcodes/dimmable_image.html +++ b/templates/shortcodes/dimmable_image.html @@ -1,8 +1,10 @@ -{% set meta = get_image_metadata(path=src, allow_missing=true) %} +{%- set meta = get_image_metadata(path=src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%} + {% if full_width | default(value=false) %}
{% endif %} - + {% if full_width | default(value=false) %}
{% endif %} diff --git a/templates/shortcodes/dual_theme_image.html b/templates/shortcodes/dual_theme_image.html index 6a33c6f1a..adea2c4b8 100644 --- a/templates/shortcodes/dual_theme_image.html +++ b/templates/shortcodes/dual_theme_image.html @@ -1,10 +1,12 @@ -{% set light_meta = get_image_metadata(path=light_src, allow_missing=true) %} -{% set dark_meta = get_image_metadata(path=dark_src, allow_missing=true) %} -{% if full_width | default(value=false) %} +{%- set light_meta = get_image_metadata(path=light_src, allow_missing=true) -%} +{%- set dark_meta = get_image_metadata(path=dark_src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%} + +{%- if full_width | default(value=false) -%}
-{% endif %} - - +{%- endif -%} + + {% if full_width | default(value=false) %}
{% endif %} diff --git a/templates/shortcodes/full_width_image.html b/templates/shortcodes/full_width_image.html index e3391be39..68c555b8b 100644 --- a/templates/shortcodes/full_width_image.html +++ b/templates/shortcodes/full_width_image.html @@ -1,4 +1,6 @@ -{% set meta = get_image_metadata(path=src, allow_missing=true) %} +{%- set meta = get_image_metadata(path=src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%} +
- +
diff --git a/templates/shortcodes/image_hover.html b/templates/shortcodes/image_hover.html index 241a5faa4..7632f56c2 100644 --- a/templates/shortcodes/image_hover.html +++ b/templates/shortcodes/image_hover.html @@ -1,13 +1,12 @@ {%- set default_meta = get_image_metadata(path=default_src, allow_missing=true) -%} {%- set hovered_meta = get_image_metadata(path=hovered_src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%} -
+
- {{ default_alt }} + {{ default_alt }}
- {{ hovered_alt }} + {{ hovered_alt }}
diff --git a/templates/shortcodes/image_toggler.html b/templates/shortcodes/image_toggler.html index 6a6499537..6dee79721 100644 --- a/templates/shortcodes/image_toggler.html +++ b/templates/shortcodes/image_toggler.html @@ -2,20 +2,18 @@ {# allowing individual interactive elements (like toggles) to function correctly. #} {# This avoids conflicts when multiple instances of the shortcode are used. #} {%- set random_id = get_random(end=100000) -%} - -{% set default_meta = get_image_metadata(path=default_src, allow_missing=true) %} -{% set toggled_meta = get_image_metadata(path=toggled_src, allow_missing=true) %} +{%- set default_meta = get_image_metadata(path=default_src, allow_missing=true) -%} +{%- set toggled_meta = get_image_metadata(path=toggled_src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%}
diff --git a/templates/shortcodes/invertible_image.html b/templates/shortcodes/invertible_image.html index ee4fc962e..d801d4dc9 100644 --- a/templates/shortcodes/invertible_image.html +++ b/templates/shortcodes/invertible_image.html @@ -1,8 +1,10 @@ -{% set meta = get_image_metadata(path=src, allow_missing=true) %} +{%- set meta = get_image_metadata(path=src, allow_missing=true) -%} +{%- set lazy_loading = lazy_loading | default(value=true) -%} + {% if full_width | default(value=false) %}
{% endif %} - -{% if full_width | default(value=false) %} + +{%- if full_width | default(value=false) -%}
-{% endif %} +{%- endif -%}