Skip to content

Commit

Permalink
shortcodes: use async and lazy for images.
Browse files Browse the repository at this point in the history
Zola v0.18 added an option to set all images with `decoding=async` and
`load=lazy`, but this only applies to `<img>` tags generated from
Markdown `![]()` syntax. This patch adds these attributes by default to
`figure` and `image` macros.
  • Loading branch information
heitorPB committed Feb 6, 2024
1 parent 03ce85e commit bef4cc9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion templates/shortcodes/figure.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if src %}
<figure class="{% if position %}{{ position }}{% else -%} center {%- endif %}" >
<img src="{{ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %}{% if style %} style="{{ style }}"{% endif %} />
<img src="{{ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %}{% if style %} style="{{ style }}"{% endif %} decoding="async" loading="lazy"/>
{% if caption %}
<figcaption class="{% if caption_position %}{{ caption_position }}{% else -%} center {%- endif %}"{% if caption_style %} style="{{ caption_style | safe }}"{% endif %}>{{ caption | markdown() | safe }}</figcaption>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/shortcodes/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{# ... then prepend the site's base URL to the image's URL. #}
{% set src = config.base_url ~ src %}
{% endif %}
<img src="{{ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %} class="{% if position %}{{ position }}{% else -%} center {%- endif %}" {%- if style %} style="{{ style | safe }}" {%- endif %} />
<img src="{{ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %} class="{% if position %}{{ position }}{% else -%} center {%- endif %}" {%- if style %} style="{{ style | safe }}" {%- endif %} decoding="async" loading="lazy"/>
{% endif %}

0 comments on commit bef4cc9

Please sign in to comment.