mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-27 15:36:22 -04:00
42 lines
1.3 KiB
HTML
42 lines
1.3 KiB
HTML
{{- /* Automatic resizing for HiDPI/retina images */ -}}
|
|
|
|
{{- $original := .Page.Resources.GetMatch (.Get "src") -}}
|
|
{{- .Scratch.Set "image" $original -}}
|
|
|
|
{{- $maxWidth := 910 -}}
|
|
{{- $setWidth := 0 -}}
|
|
|
|
{{- if .Get "width" -}}
|
|
{{- $setWidth = (int (.Get "width")) -}}
|
|
{{- $retinaWidth := (mul $setWidth 2) -}}
|
|
|
|
{{- if gt $original.Width $retinaWidth -}}
|
|
{{- $finalWidth := (printf "%dx" $retinaWidth) -}}
|
|
{{- .Scratch.Set "image" ($original.Resize $finalWidth) -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- $setWidth = $maxWidth -}}
|
|
{{- if gt $original.Width 1820 -}}
|
|
{{- .Scratch.Set "image" ($original.Resize "1820x") -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $image := .Scratch.Get "image" -}}
|
|
|
|
{{- $origRatio := (div (float $image.Height) $image.Width) -}}
|
|
{{- $displayWidth := $setWidth -}}
|
|
{{- $displayHeight := (math.Ceil (mul $origRatio $setWidth)) -}}
|
|
|
|
<p class="image">
|
|
<amp-img
|
|
{{- with .Get "alt" }} alt="{{ . | safeHTMLAttr }}" title="{{ . | safeHTMLAttr }}"{{ end }}
|
|
{{- with .Inner }} alt="{{ . | markdownify | plainify | safeHTMLAttr }}" title="{{ . | markdownify | plainify | safeHTMLAttr }}"{{ end }}
|
|
src="{{ $image.Permalink }}"
|
|
width="{{ $displayWidth }}"
|
|
height="{{ $displayHeight }}"
|
|
layout="intrinsic">
|
|
</amp-img>
|
|
</p>
|
|
|
|
{{- with .Inner }}<p class="caption">{{ $.Page.RenderString . | safeHTML }}</p>{{ end -}}
|