Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: allow relative paths for image shortcodes (#222)
- Loading branch information
Showing
9 changed files
with
158 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -%} |
Oops, something went wrong.