Skip to content

Commit

Permalink
Fix: properly link external images
Browse files Browse the repository at this point in the history
This works by prepending the site's `base_url` to internal
image paths. Image URLs are deemed to be external if they
begin with `http`.

This fix was added to a PR for the Terminimal theme.

PR: pawroman/zola-theme-terminimal#37
  • Loading branch information
goingforbrooke committed May 11, 2023
1 parent 13b2558 commit 4b447ad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion templates/shortcodes/image.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{% if src %}
<img src="{{ config.base_url ~ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %} class="{% if position %}{{ position }}{% else -%} center {%- endif %}" {%- if style %} style="{{ style | safe }}" {%- endif %} />
{# If the image's URL is internal to the site... #}
{% if src is not starting_with("http") %}
{# ... 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 %} />
{% endif %}

0 comments on commit 4b447ad

Please sign in to comment.