Skip to content

Commit

Permalink
🐛 fix: handle missing image metadata gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Apr 16, 2023
1 parent be8ec45 commit b5b50cd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion templates/macros/cards_pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a rel="noopener noreferrer" target="_blank" href={{ page.extra.link_to }}>
{% endif %}
{% if page.extra.local_image %}
{% set meta = get_image_metadata(path=page.extra.local_image) %}
{% set meta = get_image_metadata(path=page.extra.local_image, allow_missing=true) %}
<img class="card-image" alt={{ page.extra.local_image }} src="{{ get_url(path=page.extra.local_image) }}" {% if meta.width %}width="{{ meta.width }}" {% endif %} {% if meta.height %}height="{{ meta.height }}" {% endif %}>
{% elif page.extra.remote_image %}
<img class="card-image" alt={{ page.extra.remote_image }} src="{{ page.extra.remote_image }}">
Expand Down
2 changes: 1 addition & 1 deletion templates/shortcodes/dimmable_image.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% set meta = get_image_metadata(path=src) %}
{% set meta = get_image_metadata(path=src, allow_missing=true) %}
<img class="dimmable-image" src="{{ get_url(path=src) }}" {% if alt %}alt="{{ alt }}" {% endif %} {% if meta.width %}width="{{ meta.width }}" {% endif %} {% if meta.height %}height="{{ meta.height }}" {% endif %}/>
4 changes: 2 additions & 2 deletions templates/shortcodes/dual_theme_image.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set light_meta = get_image_metadata(path=light_src) %}
{% set dark_meta = get_image_metadata(path=dark_src) %}
{% set light_meta = get_image_metadata(path=light_src, allow_missing=true) %}
{% set dark_meta = get_image_metadata(path=dark_src, allow_missing=true) %}
<img src="{{ get_url(path=light_src) }}" {% if alt %}alt="{{ alt }}" {% endif %} {% if light_meta.width %}width="{{ light_meta.width }}" {% endif %} {% if light_meta.height %}height="{{ light_meta.height }}" {% endif %} class="img-light">
<img src="{{ get_url(path=dark_src) }}" {% if alt %}alt="{{ alt }}" {% endif %} {% if dark_meta.width %}width="{{ dark_meta.width }}" {% endif %} {% if dark_meta.height %}height="{{ dark_meta.height }}" {% endif %} class="img-dark">
2 changes: 1 addition & 1 deletion templates/shortcodes/invertible_image.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% set meta = get_image_metadata(path=src) %}
{% set meta = get_image_metadata(path=src, allow_missing=true) %}
<img class="invertible-image" {% 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 %}/>

0 comments on commit b5b50cd

Please sign in to comment.