1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-23 21:02:09 +00:00
seirdy.one/layouts/shortcodes/picture.html

135 lines
4.6 KiB
HTML
Raw Normal View History

{{ $light_gif := resources.GetMatch (printf "/p/%s.gif" (.Get "name")) -}}
2021-02-02 06:24:40 +00:00
{{ $light_svg := resources.GetMatch (printf "/p/%s.svg" (.Get "name")) -}}
{{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}}
2023-09-08 17:59:34 +00:00
{{ $light_jpg := resources.GetMatch (printf "/p/%s.jpg" (.Get "name")) -}}
{{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) -}}
{{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) -}}
{{ $light_jxl := resources.GetMatch (printf "/p/%s.jxl" (.Get "name")) -}}
2021-02-02 06:24:40 +00:00
{{ $dark_svg := resources.GetMatch (printf "/p/%s_dark.svg" (.Get "name")) -}}
{{ $dark_gif := resources.GetMatch (printf "/p/%s_dark.gif" (.Get "name")) -}}
{{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) -}}
2023-09-08 17:59:34 +00:00
{{ $dark_jpg := resources.GetMatch (printf "/p/%s_dark.jpg" (.Get "name")) -}}
{{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}}
{{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) -}}
{{ $dark_jxl := resources.GetMatch (printf "/p/%s_dark.jxl" (.Get "name")) -}}
2024-07-14 05:49:20 +00:00
{{ $alt := .Get "alt" -}}
2023-09-08 17:59:34 +00:00
{{- $orig_img := $light_png -}}
{{- $orig_img_type := "image/png" -}}
{{- $orig_img_dark := $dark_png -}}
{{- $orig_img_dark_type := "image/png" -}}
{{- with $light_jpg -}}
{{- $orig_img_type = "image/jpeg" -}}
{{- $orig_img = $light_jpg -}}
{{- end -}}
{{- with $light_gif -}}
{{- $orig_img_type = "image/gif" -}}
{{- $orig_img = $light_gif -}}
{{- end -}}
2023-09-08 17:59:34 +00:00
{{- with $dark_jpg -}}
{{- $orig_img_dark_type = "image/jpeg" -}}
{{- $orig_img_dark = $dark_jpg -}}
{{- end -}}
{{- with $dark_gif -}}
{{- $orig_img_dark_type = "image/gif" -}}
{{- $orig_img_dark = $dark_gif -}}
{{- end -}}
{{- $img_width := 0 -}}
{{- with .Get "width" -}}
{{- $img_width = . -}}
{{- else -}}
{{- $img_width = $orig_img.Width -}}
{{- end -}}
{{- $img_height := 0 -}}
{{- with .Get "height" -}}
{{- $img_height = . -}}
{{- else -}}
{{- $img_height = $orig_img.Height -}}
{{- end -}}
{{- with (.Get "sf") -}}
{{- $img_width = (mul $img_width . | math.Round) -}}
{{- $img_height = (mul $img_height . | math.Round ) -}}
{{- end -}}
<picture>
2022-09-24 05:37:15 +00:00
{{- if not (in site.BaseURL ".onion") -}}
2021-02-02 06:24:40 +00:00
{{ with $dark_svg -}}
{{ $dark_svg_src := partial "cache-bust.html" . -}}
2021-02-02 06:24:40 +00:00
<source
srcset="{{ $dark_svg_src.RelPermalink }}"
type="image/svg+xml"
media="screen and (prefers-color-scheme: dark)" />
2021-02-02 06:24:40 +00:00
{{ end -}}
2022-09-24 05:37:15 +00:00
{{ end -}}
{{ with $dark_jxl -}}
{{ $dark_jxl_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $dark_jxl_src.RelPermalink }}"
type="image/jxl"
media="screen and (prefers-color-scheme: dark)" />
{{ end -}}
{{ with $dark_avif -}}
{{ $dark_avif_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $dark_avif_src.RelPermalink }}"
type="image/avif"
media="screen and (prefers-color-scheme: dark)" />
{{ end -}}
{{ with $dark_webp -}}
{{ $dark_webp_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $dark_webp_src.RelPermalink }}"
type="image/webp"
media="screen and (prefers-color-scheme: dark)" />
{{ end -}}
2023-09-08 17:59:34 +00:00
{{ with $orig_img_dark -}}
{{ $orig_dark_src := partial "cache-bust.html" . -}}
<source
2023-09-08 17:59:34 +00:00
srcset="{{ $orig_dark_src.RelPermalink }}"
type="{{ $orig_img_dark_type }}"
media="screen and (prefers-color-scheme: dark)" />
{{ end -}}
2022-09-24 05:37:15 +00:00
{{- if not (in site.BaseURL ".onion") -}}
2021-02-02 06:24:40 +00:00
{{ with $light_svg -}}
{{ $light_svg_src := partial "cache-bust.html" . -}}
2021-02-02 06:24:40 +00:00
<source
srcset="{{ $light_svg_src.RelPermalink }}"
type="image/svg+xml" />
2021-02-02 06:24:40 +00:00
{{ end -}}
2022-09-24 05:37:15 +00:00
{{ end -}}
{{ with $light_jxl -}}
{{ $light_jxl_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $light_jxl_src.RelPermalink }}"
type="image/jxl" />
{{ end -}}
{{ with $light_avif -}}
{{ $light_avif_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $light_avif_src.RelPermalink }}"
type="image/avif" />
{{ end -}}
{{ with $light_webp -}}
{{ $light_webp_src := partial "cache-bust.html" . -}}
<source
srcset="{{ $light_webp_src.RelPermalink }}"
type="image/webp" />
{{ end -}}
{{ $orig_src := partial "cache-bust.html" $orig_img -}}
<source
2023-09-08 17:59:34 +00:00
srcset="{{ $orig_src.RelPermalink }}"
type="{{ $orig_img_type }}" />
<img{{ with .Get "class" }} class="{{ . }}"{{ end }}
width="{{ $img_width }}" height="{{ $img_height }}"
2024-07-14 05:49:20 +00:00
src="{{ $orig_src.Permalink }}" alt="{{ $alt }}"
{{ with .Parent -}}
2022-05-06 17:30:11 +00:00
{{ if eq .Name "transcribed-image-figure" -}}
{{ with .Get "id" -}}
aria-describedby="transcript-{{ . }}"
2022-05-06 17:30:11 +00:00
{{ end -}}
{{ end -}}
{{ if or (eq .Name "image-figure") (eq .Name "transcribed-image-figure") -}}
itemprop="image contentUrl url"
2022-05-06 17:30:11 +00:00
{{ end -}}
{{- end -}}
decoding="async" />
</picture>{{- /* Strip trailing newline: https://github.com/gohugoio/hugo/issues/1753 */ -}}