summaryrefslogtreecommitdiffstats
path: root/templates/shortcodes/figure.html
blob: e56957e8583302c7c496b0ff48844c0803cda9af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{% if img is matching("\.(jpg|jpeg|png)$") -%}
	{% for asset in page.assets %}
		{% if asset is ending_with(img) %}
			{% set_global img = asset %}
			{% break %}
		{% endif %}
	{% endfor %}
	{% set meta = get_image_metadata(path=img) %}
	{% set scale = meta.height / 500 %}
	{% if scale > 1 %}
		{% set size_y = 500 %}
		{% set size_x = meta.width / scale %}
	{% else %}
		{% set size_y = meta.height %}
		{% set size_x = meta.width %}
	{% endif %}
	{% set img_url = resize_image(path=img, height=size_y, op="fit_height") %}
	{% if size_x < 400 %}
		{% set xclass = "prefer-left" %}
	{% endif %}
{% else %}
	{% set img_url = get_url(path=page.path ~ img) %}
{% endif %}
<div class="figure {% if xclass %}{{ xclass }}{% endif %}">
	<img src="{{ img_url | safe }}"
			{% if alt %}alt="[{{ alt }}]"{% endif %}
			>
	<div class="caption">
		{{ body | markdown | safe}}
	</div>
</div>