-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(shortcodes): support URLs for image source
- Loading branch information
Showing
9 changed files
with
132 additions
and
88 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,21 +1,28 @@ | ||
{%- 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) -%} | ||
{%- set is_remote = src is starting_with("http") -%} | ||
|
||
{#- 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 -%} | ||
{#- Determine image path based on whether the src is remote or local -#} | ||
{%- if is_remote -%} | ||
{%- set image_url = src -%} | ||
{%- else -%} | ||
{%- set image_path = relative_path -%} | ||
{%- 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_url = get_url(path=src) -%} | ||
{%- else -%} | ||
{%- set image_url = get_url(path=relative_path) -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
|
||
{%- set lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
{%- if full_width | default(value=false) -%} | ||
{%- if full_width -%} | ||
<div class="full-width"> | ||
{%- 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) -%} | ||
<img class="dimmable-image" src="{{ image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if not is_remote and meta.width %} width="{{ meta.width }}"{% endif %}{% if not is_remote and meta.height %} height="{{ meta.height }}" {% endif %}/> | ||
{%- if full_width -%} | ||
</div> | ||
{%- 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,30 +1,37 @@ | ||
{%- 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 lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
{%- 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 -%} | ||
{# Handling for light mode image #} | ||
{%- if light_src is starting_with("http") -%} | ||
{%- set light_image_url = light_src -%} | ||
{%- else -%} | ||
{%- set light_image_path = relative_light_path -%} | ||
{%- set relative_light_path = colocated_path ~ light_src -%} | ||
{%- set light_meta = get_image_metadata(path=relative_light_path, allow_missing=true) -%} | ||
{%- if not light_meta -%} | ||
{%- set light_image_url = get_url(path=light_src) -%} | ||
{%- else -%} | ||
{%- set light_image_url = get_url(path=relative_light_path) -%} | ||
{%- endif -%} | ||
{%- 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 -%} | ||
{# Handling for dark mode image #} | ||
{%- if dark_src is starting_with("http") -%} | ||
{%- set dark_image_url = dark_src -%} | ||
{%- else -%} | ||
{%- set dark_image_path = relative_dark_path -%} | ||
{%- set relative_dark_path = colocated_path ~ dark_src -%} | ||
{%- set dark_meta = get_image_metadata(path=relative_dark_path, allow_missing=true) -%} | ||
{%- if not dark_meta -%} | ||
{%- set dark_image_url = get_url(path=dark_src) -%} | ||
{%- else -%} | ||
{%- set dark_image_url = get_url(path=relative_dark_path) -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
|
||
{%- set lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
{%- if full_width | default(value=false) -%} | ||
{%- if full_width -%} | ||
<div class="full-width"> | ||
{%- endif -%} | ||
<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) -%} | ||
<img src="{{ light_image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if light_meta and light_meta.width %} width="{{ light_meta.width }}"{% endif %}{% if light_meta and light_meta.height %} height="{{ light_meta.height }}" {% endif %} class="img-light"> | ||
<img src="{{ dark_image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}{% if dark_meta and dark_meta.width %} width="{{ dark_meta.width }}"{% endif %}{% if dark_meta and dark_meta.height %} height="{{ dark_meta.height }}" {% endif %} class="img-dark"> | ||
{%- if full_width -%} | ||
</div> | ||
{%- 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,17 +1,22 @@ | ||
{%- 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) -%} | ||
{#- Set paths based on whether the src is remote or local -#} | ||
{%- if src is starting_with("http") -%} | ||
{%- set image_url = src -%} | ||
{%- else -%} | ||
{%- 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 -%} | ||
{#- 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_url = get_url(path=src) -%} | ||
{%- else %} | ||
{%- set image_url = get_url(path=relative_path) -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
|
||
{%- set lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
<div class="full-width"> | ||
<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 %}/> | ||
<img src="{{ image_url }}"{% 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> |
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,30 +1,37 @@ | ||
{%- 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 lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
{%- 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 -%} | ||
{#- Direct or relative URL handling for default image -#} | ||
{%- if default_src is starting_with("http") -%} | ||
{%- set default_image_url = default_src -%} | ||
{%- else -%} | ||
{%- set default_image_path = relative_default_path -%} | ||
{%- set relative_default_path = colocated_path ~ default_src -%} | ||
{%- set default_meta = get_image_metadata(path=relative_default_path, allow_missing=true) -%} | ||
{%- if not default_meta -%} | ||
{%- set default_image_url = get_url(path=default_src) -%} | ||
{%- else -%} | ||
{%- set default_image_url = get_url(path=relative_default_path) -%} | ||
{%- endif -%} | ||
{%- 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 -%} | ||
{#- Direct or relative URL handling for hovered image -#} | ||
{%- if hovered_src is starting_with("http") -%} | ||
{%- set hovered_image_url = hovered_src -%} | ||
{%- else -%} | ||
{%- set hovered_image_path = relative_hovered_path -%} | ||
{%- set relative_hovered_path = colocated_path ~ hovered_src -%} | ||
{%- set hovered_meta = get_image_metadata(path=relative_hovered_path, allow_missing=true) -%} | ||
{%- if not hovered_meta -%} | ||
{%- set hovered_image_url = get_url(path=hovered_src) -%} | ||
{%- else -%} | ||
{%- set hovered_image_url = get_url(path=relative_hovered_path) -%} | ||
{%- endif -%} | ||
{%- 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-hover-container{% if full_width %} full-width{% endif %}"> | ||
<div class="image-default"> | ||
<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 %}> | ||
<img src="{{ default_image_url }}"{% 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_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 %}> | ||
<img src="{{ hovered_image_url }}"{% if lazy_loading %} loading="lazy"{% endif %}{% 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> |
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,21 +1,26 @@ | ||
{%- 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 -%} | ||
{#- Determine if src is a remote URL or a local path -#} | ||
{%- if src is starting_with("http") -%} | ||
{%- set image_url = src -%} | ||
{%- else -%} | ||
{%- set image_path = relative_path -%} | ||
{%- 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_url = get_url(path=src) -%} | ||
{%- else %} | ||
{%- set image_url = get_url(path=relative_path) -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
|
||
{%- set lazy_loading = lazy_loading | default(value=true) -%} | ||
|
||
{%- if full_width | default(value=false) -%} | ||
{%- if full_width -%} | ||
<div class="full-width"> | ||
{%- 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) -%} | ||
<img class="invertible-image" src="{{ image_url }}"{% 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 -%} | ||
</div> | ||
{%- endif -%} |