mirror of
https://github.com/welpo/tabi.git
synced 2026-06-13 23:07:36 +02:00
✨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:
parent
1be3fa886c
commit
ec31c71b38
9 changed files with 41 additions and 30 deletions
|
|
@ -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) -%}
|
||||
|
||||
<div class="image-toggler-container {% if full_width | default(value=false) %}full-width{% endif %}">
|
||||
<input type="checkbox" id="toggle-img-{{ random_id }}" class="image-toggler-toggle">
|
||||
<label for="toggle-img-{{ random_id }}" class="image-label">
|
||||
<div class="image-default">
|
||||
<img src="{{ get_url(path=default_src) }}" alt="{{ default_alt }}"
|
||||
width="{{ default_meta.width }}" height="{{ default_meta.height }}">
|
||||
<img src="{{ get_url(path=default_src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if default_alt %} alt="{{ default_alt }}"{% endif %}{% if default_meta.width %} width="{{ default_meta.width }}"{% endif %}{% if default_meta.height %} height="{{ default_meta.height }}"{% endif %}>
|
||||
</div>
|
||||
<div class="image-toggled">
|
||||
<img src="{{ get_url(path=toggled_src) }}" alt="{{ toggled_alt }}"
|
||||
width="{{ toggled_meta.width }}" height="{{ toggled_meta.height }}">
|
||||
<img src="{{ get_url(path=toggled_src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if toggled_alt %} alt="{{ toggled_alt }}"{% endif %}{% if toggled_meta.width %} width="{{ toggled_meta.width }}"{% endif %}{% if toggled_meta.height %} height="{{ toggled_meta.height }}"{% endif %}>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue