{{- /* render-image.html (markup): Features: - Pass images on page bundles through Hugo pipes - Style them according to Alpha's design - OCD error reporting enabled Repo: https://github.com/oxypteros/alpha */ -}} {{- $destination := .Destination }} {{- $image := .Page.Resources.GetMatch (printf "*%s*" $destination) }} {{- if $image }} {{- $originalWidth := $image.Width }} {{- $small := cond (ge $originalWidth 286) ($image.Resize "286x webp q90") ($image) }} {{- $small2x := cond (ge $originalWidth 572) ($image.Resize "572x webp q90") ($image) }} {{- $medium := cond (ge $originalWidth 710) ($image.Resize "710x webp q90") ($image) }} {{- $medium2x := cond (ge $originalWidth 1420) ($image.Resize "1420x webp q90") ($image) }} {{- /* Generate the srcset dynamically based on available sizes */}} {{- $srcset := slice }} {{- if ge $originalWidth 286 }} {{ $srcset = $srcset | append (printf "%s 286w" $small.RelPermalink) }} {{ end }} {{- if ge $originalWidth 572 }} {{ $srcset = $srcset | append (printf "%s 572w" $small2x.RelPermalink) }} {{ end }} {{- if ge $originalWidth 710 }} {{ $srcset = $srcset | append (printf "%s 710w" $medium.RelPermalink) }} {{ end }} {{- if ge $originalWidth 1420 }} {{ $srcset = $srcset | append (printf "%s 1420w" $medium2x.RelPermalink) }} {{ end }} {{- $finalSrcset := delimit $srcset ", " }} {{- /* Adjust sizes dynamically */}} {{- $sizes := "(min-width: 800px) 708px, 92.08vw" }} {{- if lt $originalWidth 286 }} {{- $sizes = printf "%dpx" $originalWidth }} {{- else if lt $originalWidth 572 }} {{- $sizes = printf "(min-width: 580px) %dpx, calc(93.85vw - 16px)" $originalWidth }} {{- else if lt $originalWidth 710 }} {{- $sizes = printf "(min-width: 680px) %dpx, 92.22vw" $originalWidth }} {{- end }} {{- /* OCD error reporting for missing image alt */}} {{- if eq .PlainText "" }} {{ $errorCode := "ocd-md-101" }} {{ $page := .Page.RelPermalink }} {{ $errorMessage := printf "Missing alt from image - %s" $destination }} {{ $logMessage := printf "OcdError:%s (%s: %s)" $errorCode $page $errorMessage }} {{ warnf "%s" $logMessage }} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{ i18n "OcdImageAltMissing" }}

{{ i18n "OcdImageAltText" . | default "Alternative text is missing from image" }} {{ $destination }} {{ i18n "OcdOn" . | default "on:" }} {{ .Page.Title }}


*{{ i18n "OcdImageAltMissingSolution" . | default "Enter an image description in the markdown image instruction." }}

{{- end }} {{- end }}
{{- with .Title }}
{{ . }}
{{ end }}
{{- else }} {{- /* OCD error reporting for image not found */}} {{ $errorCode := "ocd-md-100" }} {{ $page := .Page.RelPermalink }} {{ $errorMessage := printf "Image not found - %s" $destination }} {{ $logMessage := printf "OcdError:%s (%s: %s)" $errorCode $page $errorMessage }} {{ warnf "%s" $logMessage }} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{ i18n "OcdImageError" }}

{{ i18n "OcdImageNotFound" }} {{ .Page.Title }} ( {{ $destination }} )


*{{ i18n "OcdImageMissingSolution" . | default "Confirm the image exists and the name in the markdown matches perfectly." }}

{{- end }} {{- end }}