diff options
| author | Jieiku | 2023-08-09 18:44:31 -0700 |
|---|---|---|
| committer | Jieiku | 2023-08-09 18:44:31 -0700 |
| commit | 729f7cda12340aabce5d0faab8d306b5e0d59568 (patch) | |
| tree | 9b0b66cf2e1fbdfc08bad3252eb3dd1bf48b84d6 /templates/shortcodes/imgswap.html | |
| parent | 24e4b49edfbbe0b51786606f9c434e8ba860e28d (diff) | |
| download | abridge-729f7cda12340aabce5d0faab8d306b5e0d59568.tar.gz abridge-729f7cda12340aabce5d0faab8d306b5e0d59568.tar.bz2 abridge-729f7cda12340aabce5d0faab8d306b5e0d59568.zip | |
imghover > imgswap, reduce complexity, fix CSP
Diffstat (limited to 'templates/shortcodes/imgswap.html')
| -rw-r--r-- | templates/shortcodes/imgswap.html | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/templates/shortcodes/imgswap.html b/templates/shortcodes/imgswap.html new file mode 100644 index 0000000..f8c983c --- /dev/null +++ b/templates/shortcodes/imgswap.html @@ -0,0 +1,59 @@ +<div class="img-swap-div"> + {%- set dirtest = main_src | trim_start_matches(pat="./") %} + {%- if dirtest is containing("/") %} + {%- set reldir = true %} + {%- endif %} + + {%- if main_src is starting_with("./") and reldir %} {# Relative Path #} + {%- set path = main_src | trim_start_matches(pat="./") | split(pat="/") | slice(end=-1) | join(sep="/") | trim_start_matches(pat="/") %} + {%- set path = path ~ "/" %} + + {%- elif main_src is starting_with("/") %} {# Root Path #} + {%- set rootpath = main_src | split(pat="/") | slice(end=-1) | join(sep="/") %} + {%- set path = config.base_url ~ rootpath ~ "/" %} + + {%- else %} {# Same Directory Path #} + {%- set path = "" %} + + {%- endif %} + + {%- if not w or not h %} + {%- set metafile = page.path ~ path ~ main_src %} + {%- set meta = get_image_metadata(path=metafile) %} + {%- set w = meta.width %} + {%- set h = meta.height %} + {%- endif %} + + {%- set img = main_src | split(pat="/") | last %} + {%- set name = img | split(pat=".") | first %} + <img src="{{ path | safe }}{{ img | safe }}" class="img-main{% if class %} {{class}}{% endif %}"{% if alt %} alt="{{alt}}"{% endif %}{% if w %} width="{{w}}"{% endif %}{% if h %} height="{{h}}"{% endif %} /> + + {%- set dirtest = swap_src | trim_start_matches(pat="./") %} + {%- if dirtest is containing("/") %} + {%- set reldir = true %} + {%- endif %} + + {%- if swap_src is starting_with("./") and reldir %} {# Relative Path #} + {%- set path = swap_src | trim_start_matches(pat="./") | split(pat="/") | slice(end=-1) | join(sep="/") | trim_start_matches(pat="/") %} + {%- set path = path ~ "/" %} + + {%- elif swap_src is starting_with("/") %} {# Root Path #} + {%- set rootpath = swap_src | split(pat="/") | slice(end=-1) | join(sep="/") %} + {%- set path = config.base_url ~ rootpath ~ "/" %} + + {%- else %} {# Same Directory Path #} + {%- set path = "" %} + + {%- endif %} + + {%- if not w or not h %} + {%- set metafile = page.path ~ path ~ swap_src %} + {%- set meta = get_image_metadata(path=metafile) %} + {%- set w = meta.width %} + {%- set h = meta.height %} + {%- endif %} + + {%- set img = swap_src | split(pat="/") | last %} + {%- set name = img | split(pat=".") | first %} + <img src="{{ path | safe }}{{ img | safe }}" class="img-swap{% if class %} {{class}}{% endif %}"{% if alt %} alt="{{alt}}"{% endif %}{% if w %} width="{{w}}"{% endif %}{% if h %} height="{{h}}"{% endif %} /> +</div> |
