From 61f2e1c3ac343163a5361686ad529c7039387310 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Sun, 20 Aug 2023 22:37:18 -0700 Subject: fix image shortcodes for multilingual, and other optimizations --- templates/shortcodes/img.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'templates/shortcodes/img.html') diff --git a/templates/shortcodes/img.html b/templates/shortcodes/img.html index a5a0541..d599ba0 100644 --- a/templates/shortcodes/img.html +++ b/templates/shortcodes/img.html @@ -6,7 +6,12 @@ {%- set path = src | trim_start_matches(pat="./") | split(pat="/") | slice(end=-1) | join(sep="/") | trim_start_matches(pat="/") %} {%- set path = path ~ "/" %} {%- if not w or not h %} - {%- set meta = get_image_metadata(path=page.path ~ path ~ img) %} + {%- if lang != config.default_language %} + {%- set metapath = page.path ~ path ~ img | replace(from=page.path | truncate(length=4, end=""), to="/") %} + {%- else %} + {%- set metapath = page.path ~ path ~ img %} + {%- endif %} + {%- set meta = get_image_metadata(path=metapath) %} {%- set w = meta.width %} {%- set h = meta.height %} {%- endif %} @@ -15,7 +20,8 @@ {%- set rootpath = src | split(pat="/") | slice(end=-1) | join(sep="/") %} {%- set path = config.base_url ~ rootpath ~ "/" %} {%- if not w or not h %} - {%- set meta = get_image_metadata(path=rootpath ~ "/" ~ img) %} + {%- set metapath = rootpath ~ "/" ~ img %} + {%- set meta = get_image_metadata(path=metapath) %} {%- set w = meta.width %} {%- set h = meta.height %} {%- endif %} @@ -23,7 +29,12 @@ {%- else %} {# Same Directory Path #} {%- set path = page.path %} {%- if not w or not h %} - {%- set meta = get_image_metadata(path=page.path ~ img) %} + {%- if lang != config.default_language %} + {%- set metapath = page.path ~ img | replace(from=page.path | truncate(length=4, end=""), to="/") %} + {%- else %} + {%- set metapath = page.path ~ img %} + {%- endif %} + {%- set meta = get_image_metadata(path=metapath) %} {%- set w = meta.width %} {%- set h = meta.height %} {%- endif %} -- cgit v1.3.1