summaryrefslogtreecommitdiff
path: root/layouts/_markup/render-image.html
blob: 49c9fceee7ed6f76bba4c716a343e6f773efd995 (plain)
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
{{- $src := .Destination -}}
{{- $alt := .Text | default "" -}}
{{- $caption := .Title | default "" -}}
{{- $class := .Attributes.class | default "" -}}

{{- if and (not (strings.HasPrefix $src "https://")) (not (strings.HasPrefix $src "http://")) -}}
    {{- if not (strings.HasPrefix $src "/") -}}
        {{- $src = printf "%s/%s%s" site.Params.assetBaseUrl .Page.File.Dir $src -}}
    {{- else -}}
        {{- $src = printf "%s%s" site.Params.assetBaseUrl $src -}}
    {{- end -}}
{{- end -}}

<figure>
    <img
        class="lazy {{ $class }}" loading="lazy"
        src="{{ $src }}" alt="{{ $alt }}"
        data-libra
    />
    {{- if $caption }}
    <figcaption>
        <h4>{{ $caption | markdownify }}</h4>
    </figcaption>
    {{- end }}
</figure>