feat(shortcodes): add lazy loading & make alt optional

- Implement lazy loading in all image shortcodes, enabled by default.

- Make alt attributes optional across all image shortcodes.

- Optimize HTML output by managing whitespace.
This commit is contained in:
welpo 2023-08-26 01:48:16 +02:00
parent 1be3fa886c
commit ec31c71b38
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
9 changed files with 41 additions and 30 deletions

View file

@ -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) -%}
<div class="full-width">
<img {% if src %}src="{{ get_url(path=src) }}" {% endif %} {% if alt %}alt="{{ alt }}" {% endif %} {% if meta.width %}width="{{ meta.width }}" {% endif %} {% if meta.height %}height="{{ meta.height }}" {% endif %}/>
<img src="{{ get_url(path=src) }}"{% if alt %} alt="{{ alt }}"{% endif %}{% if meta.width %} width="{{ meta.width }}"{% endif %}{% if meta.height %} height="{{ meta.height }}"{% endif %}{% if lazy_loading %} loading="lazy"{% endif %}/>
</div>