aboutsummaryrefslogtreecommitdiff
path: root/templates/shortcodes/img.html
diff options
context:
space:
mode:
authorJieiku2022-03-27 19:19:28 -0700
committerJieiku2022-03-27 19:19:28 -0700
commit2ef7c0ec1ff976b807691fea23eaaf5ea1e93bc9 (patch)
tree33dda7250a49739153f501dbdec7c26792d87964 /templates/shortcodes/img.html
downloadabridge-2ef7c0ec1ff976b807691fea23eaaf5ea1e93bc9.tar.gz
abridge-2ef7c0ec1ff976b807691fea23eaaf5ea1e93bc9.tar.bz2
abridge-2ef7c0ec1ff976b807691fea23eaaf5ea1e93bc9.zip
init
Diffstat (limited to 'templates/shortcodes/img.html')
-rw-r--r--templates/shortcodes/img.html42
1 files changed, 42 insertions, 0 deletions
diff --git a/templates/shortcodes/img.html b/templates/shortcodes/img.html
new file mode 100644
index 0000000..94cb9fa
--- /dev/null
+++ b/templates/shortcodes/img.html
@@ -0,0 +1,42 @@
+{# {{ img(path="", alt="", caption="", extended_width_pct=1.3, quality=90) }} #}
+
+{# container_width = (pixel size, px) * (.container's max-width) #}
+{% set container_width = 16 * 42 %}
+
+{# figure_width = container_width - (figure margin_blocks) #}
+{% set figure_width = container_width - (40 * 2) %}
+
+{% if path is starting_with("./") %}
+ {% set relative_path = page.relative_path | split(pat="/") | slice(end=-1) | join(sep="/") %}
+ {% set img_path = path | trim_start_matches(pat="./") %}
+ {% set img_path = relative_path ~ "/" ~ img_path %}
+{% else %}
+ {% set img_path = path %}
+{% endif %}
+
+{% if path is not ending_with(".svg") %}
+ {% set resize = true %}
+ {% set image_quality = 90 %}
+ {% if quality %}
+ {% set image_quality = quality %}
+ {% endif %}
+
+ {% if extended_width_pct %}
+ {% if extended_width_pct == -1 %}
+ {# adjust extended width to container width #}
+ {% set extended_width_pct = 0.042 %}
+ {% endif %}
+ {% set _width = config.extra.images.max_width - figure_width %}
+ {% set extended_width = (extended_width_pct * _width + figure_width) | round | int %}
+ {% if extended_width > config.extra.images.max_width %}
+ {% set extended_width = config.extra.images.max_width %}
+ {% endif %}
+ {% set resized_image = resize_image(path=img_path, width=extended_width, op="fit_width", quality=image_quality) %}
+ {% else %}
+ {% set resized_image = resize_image(path=img_path, width=figure_width, op="fit_width", quality=image_quality) %}
+ {% endif %}
+{% endif %}
+<figure>
+ <img src="{% if resize %}{{ resized_image.url }}{% else %}{{ path }}{% endif %}" {% if alt %}alt="{{alt}}"{% endif %}/>
+ {% if caption %}<figcaption>{{ caption | safe }}</figcaption>{% endif %}
+</figure>