✨ feat: allow relative paths for image shortcodes (#222)
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_path = colocated_path ~ src -%}
|
||||
{%- set meta = get_image_metadata(path=relative_path, allow_missing=true) -%}
|
||||
|
||||
{#- Fallback to absolute path if relative path doesn't work -#}
|
||||
{%- if not meta -%}
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set image_path = src -%}
|
||||
{%- else -%}
|
||||
{%- set image_path = relative_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set lazy_loading = lazy_loading | default(value=true) -%}
|
||||
|
||||
{% if full_width | default(value=false) %}
|
||||
{%- if full_width | default(value=false) -%}
|
||||
<div class="full-width">
|
||||
{% endif %}
|
||||
<img class="dimmable-image" src="{{ get_url(path=src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if meta.width %} width="{{ meta.width }}"{% endif %}{% if meta.height %} height="{{ meta.height }}" {% endif %}/>
|
||||
{% if full_width | default(value=false) %}
|
||||
{%- endif -%}
|
||||
<img class="dimmable-image" src="{{ get_url(path=image_path) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if meta.width %} width="{{ meta.width }}"{% endif %}{% if meta.height %} height="{{ meta.height }}" {% endif %}/>
|
||||
{%- if full_width | default(value=false) -%}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- endif -%}
|
||||
|
@@ -1,12 +1,30 @@
|
||||
{%- set light_meta = get_image_metadata(path=light_src, allow_missing=true) -%}
|
||||
{%- set dark_meta = get_image_metadata(path=dark_src, allow_missing=true) -%}
|
||||
{%- set colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_light_path = colocated_path ~ light_src -%}
|
||||
{%- set relative_dark_path = colocated_path ~ dark_src -%}
|
||||
|
||||
{%- set light_meta = get_image_metadata(path=relative_light_path, allow_missing=true) -%}
|
||||
{%- if not light_meta -%}
|
||||
{%- set light_meta = get_image_metadata(path=light_src, allow_missing=true) -%}
|
||||
{%- set light_image_path = light_src -%}
|
||||
{%- else -%}
|
||||
{%- set light_image_path = relative_light_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set dark_meta = get_image_metadata(path=relative_dark_path, allow_missing=true) -%}
|
||||
{%- if not dark_meta -%}
|
||||
{%- set dark_meta = get_image_metadata(path=dark_src, allow_missing=true) -%}
|
||||
{%- set dark_image_path = dark_src -%}
|
||||
{%- else -%}
|
||||
{%- set dark_image_path = relative_dark_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set lazy_loading = lazy_loading | default(value=true) -%}
|
||||
|
||||
{%- if full_width | default(value=false) -%}
|
||||
<div class="full-width">
|
||||
{%- endif -%}
|
||||
<img src="{{ get_url(path=light_src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% 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 lazy_loading %} loading="lazy"{% endif %}{% 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">
|
||||
{% if full_width | default(value=false) %}
|
||||
<img src="{{ get_url(path=light_image_path) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% 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_image_path) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% 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">
|
||||
{%- if full_width | default(value=false) -%}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- endif -%}
|
||||
|
@@ -1,6 +1,17 @@
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_path = colocated_path ~ src -%}
|
||||
{%- set meta = get_image_metadata(path=relative_path, allow_missing=true) -%}
|
||||
|
||||
{#- Fallback to absolute path if relative path doesn't work -#}
|
||||
{%- if not meta -%}
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set image_path = src -%}
|
||||
{%- else %}
|
||||
{%- set image_path = relative_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set lazy_loading = lazy_loading | default(value=true) -%}
|
||||
|
||||
<div class="full-width">
|
||||
<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 %}/>
|
||||
<img src="{{ get_url(path=image_path) }}"{% 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>
|
||||
|
@@ -1,12 +1,30 @@
|
||||
{%- set default_meta = get_image_metadata(path=default_src, allow_missing=true) -%}
|
||||
{%- set hovered_meta = get_image_metadata(path=hovered_src, allow_missing=true) -%}
|
||||
{%- set colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_default_path = colocated_path ~ default_src -%}
|
||||
{%- set relative_hovered_path = colocated_path ~ hovered_src -%}
|
||||
|
||||
{%- set default_meta = get_image_metadata(path=relative_default_path, allow_missing=true) -%}
|
||||
{%- if not default_meta -%}
|
||||
{%- set default_meta = get_image_metadata(path=default_src, allow_missing=true) -%}
|
||||
{%- set default_image_path = default_src -%}
|
||||
{%- else -%}
|
||||
{%- set default_image_path = relative_default_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set hovered_meta = get_image_metadata(path=relative_hovered_path, allow_missing=true) -%}
|
||||
{%- if not hovered_meta -%}
|
||||
{%- set hovered_meta = get_image_metadata(path=hovered_src, allow_missing=true) -%}
|
||||
{%- set hovered_image_path = hovered_src -%}
|
||||
{%- else -%}
|
||||
{%- set hovered_image_path = relative_hovered_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set lazy_loading = lazy_loading | default(value=true) -%}
|
||||
|
||||
<div class="image-hover-container{% if full_width | default(value=false) %} full-width{% endif %}">
|
||||
<div class="image-default">
|
||||
<img src="{{ get_url(path=default_src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if hovered_alt %} alt="{{ default_alt }}"{% endif %}{% if default_meta.width %} width="{{ default_meta.width }}"{% endif %}{% if default_meta.height %} height="{{ default_meta.height }}"{% endif %}>
|
||||
<img src="{{ get_url(path=default_image_path) }}"{% 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-hovered">
|
||||
<img src="{{ get_url(path=hovered_src) }}"{% if hovered_alt %} alt="{{ hovered_alt }}"{% endif %}{% if hovered_meta.width %} width="{{ hovered_meta.width }}"{% endif %}{% if hovered_meta.height %} height="{{ hovered_meta.height }}"{% endif %}>
|
||||
<img src="{{ get_url(path=hovered_image_path) }}"{% if hovered_alt %} alt="{{ hovered_alt }}"{% endif %}{% if hovered_meta.width %} width="{{ hovered_meta.width }}"{% endif %}{% if hovered_meta.height %} height="{{ hovered_meta.height }}"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -2,18 +2,36 @@
|
||||
{# 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 colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_default_path = colocated_path ~ default_src -%}
|
||||
{%- set relative_toggled_path = colocated_path ~ toggled_src -%}
|
||||
|
||||
{%- set default_meta = get_image_metadata(path=relative_default_path, allow_missing=true) -%}
|
||||
{%- if not default_meta -%}
|
||||
{%- set default_meta = get_image_metadata(path=default_src, allow_missing=true) -%}
|
||||
{%- set default_image_path = default_src -%}
|
||||
{%- else -%}
|
||||
{%- set default_image_path = relative_default_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set toggled_meta = get_image_metadata(path=relative_toggled_path, allow_missing=true) -%}
|
||||
{%- if not toggled_meta -%}
|
||||
{%- set toggled_meta = get_image_metadata(path=toggled_src, allow_missing=true) -%}
|
||||
{%- set toggled_image_path = toggled_src -%}
|
||||
{%- else -%}
|
||||
{%- set toggled_image_path = relative_toggled_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- 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) }}"{% 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 %}>
|
||||
<img src="{{ get_url(path=default_image_path) }}"{% 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) }}"{% 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 %}>
|
||||
<img src="{{ get_url(path=toggled_image_path) }}"{% 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>
|
||||
|
@@ -1,10 +1,21 @@
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set colocated_path = page.colocated_path | default(value="") -%}
|
||||
{%- set relative_path = colocated_path ~ src -%}
|
||||
{%- set meta = get_image_metadata(path=relative_path, allow_missing=true) -%}
|
||||
|
||||
{#- Fallback to absolute path if relative path doesn't work -#}
|
||||
{%- if not meta -%}
|
||||
{%- set meta = get_image_metadata(path=src, allow_missing=true) -%}
|
||||
{%- set image_path = src -%}
|
||||
{%- else -%}
|
||||
{%- set image_path = relative_path -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set lazy_loading = lazy_loading | default(value=true) -%}
|
||||
|
||||
{% if full_width | default(value=false) %}
|
||||
{%- if full_width | default(value=false) -%}
|
||||
<div class="full-width">
|
||||
{% endif %}
|
||||
<img class="invertible-image" src="{{ get_url(path=src) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if meta.width %} width="{{ meta.width }}"{% endif %}{% if meta.height %} height="{{ meta.height }}" {% endif %}/>
|
||||
{%- endif -%}
|
||||
<img class="invertible-image" src="{{ get_url(path=image_path) }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if meta.width %} width="{{ meta.width }}"{% endif %}{% if meta.height %} height="{{ meta.height }}" {% endif %}/>
|
||||
{%- if full_width | default(value=false) -%}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
|
Reference in New Issue
Block a user