Omphaloskepsis-2/layouts/partials/media/picture.html

54 lines
1.6 KiB
HTML
Raw Normal View History

2024-04-02 20:36:21 +01:00
<!--
Render an image in a context-appropriate format and size.
2025-06-04 17:57:21 +02:00
@params src Image media file.
@params raw Force raw image only. Optional.
2024-04-02 20:36:21 +01:00
-->
<!-- Variable assignment -->
2025-06-04 17:57:21 +02:00
{{- $src := .src -}}
{{- $hint := default ( index $src.Params "hint" ) "" }}
{{- $format := cond ( and ( isset . "raw" ) .raw ) "" "webp" -}}
2024-04-02 20:36:21 +01:00
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
2025-05-14 17:29:46 +02:00
2024-04-02 20:36:21 +01:00
<!-- Rendering -->
2025-05-14 17:29:46 +02:00
<picture
class="picture"
itemprop="image"
>
{{ if $isResizable -}}
2025-06-04 17:57:21 +02:00
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "same" "format" $format ) $src.Title -}}"
2024-04-02 20:36:21 +01:00
/>
2025-06-04 17:57:21 +02:00
{{- if gt $src.Width 1200 -}}
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "1200x" "format" $format ) ( printf "%s-1200x" $src.Title ) -}}"
media="(max-width: 1200px)"
/>
{{- end -}}
{{- if gt $src.Width 800 -}}
<source
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "800x" "format" $format ) ( printf "%s-800x" $src.Title ) -}}"
media="(max-width: 800px)"
/>
{{- end -}}
2025-05-14 17:29:46 +02:00
{{- end }}
<img
class="u-photo picture__image"
{{ if not $isResizable -}}
src="{{- $src.RelPermalink -}}"
{{- else -}}
2025-06-04 17:57:21 +02:00
src="{{- partialCached "images/get-image.html" ( dict "img" $src "format" $format ) $src.Title -}}"
width="{{- $src.Width -}}"
height="{{- $src.Height -}}"
2025-05-14 17:29:46 +02:00
{{- end }}
{{ with $src.Params.alt -}}alt="{{- . -}}"{{- end }}
{{ with $src.Params.title -}}title="{{- . -}}"{{- end }}
loading="lazy"
role="img"
/>
2025-01-05 17:28:25 +01:00
</picture>