Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/rmaguiar/hugo-theme-color-your-world.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/_default/_markup/render-image.html')
-rw-r--r--layouts/_default/_markup/render-image.html113
1 files changed, 66 insertions, 47 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 6f9ae60..77af37a 100644
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -2,8 +2,14 @@
{{ $altText := .Text }}
{{ $class := .Page.Param "markupImgClass" }}
-<!-- Get image processing options -->
-{{ $imageProc := .Page.Scratch.Get "imageProc" }}
+
+<!-- Image processing configuration -->
+{{ $imgProcConfig := false }}
+
+{{ with .Page }}
+ {{ $imgProcConfig = partialCached "utilities/image-processing-config" . }}
+{{ end }}
+
<!-- Default image path -->
{{ $imgPath := .Page.Param "imgPath" }}
@@ -12,58 +18,71 @@
{{ $file = path.Join $imgPath $file }}
{{ end }}
-<!-- Assume file is local if found -->
-{{ with $.Page.Resources.GetMatch $file }}
+{{ $inputFile := .Page.Resources.GetMatch $file }}
- <!-- If image width is equal or greater than X, process it -->
- {{ if ge .Width $imageProc.markupAutoResizeWidth }}
- {{ $mediumRes := (index $imageProc.mediumRes 0) }}
+{{ with partial "utilities/image-processing" (dict "context" . "input" $inputFile "config" $imgProcConfig) }}
- {{ $outputSet := slice }}
- {{ $inputFile := . }}
+ {{ if .sets.default }}
+
+ <picture>
- {{ range $imageProc }}
- {{ if reflect.IsSlice . }}
- {{ $outputSet = $outputSet | append (printf "%s %s" (($inputFile.Resize (index . 0)).RelPermalink) (index . 1)) }}
+ <!-- Extra sets -->
+ {{ range .sets.extra }}
+ <source
+ srcset='{{ delimit .source ", " }}'
+ type="{{ .mediaType }}"
+ >
{{ end }}
- {{ end }}
+
+ <!-- Default set -->
+ <source
+ srcset='{{ delimit .sets.default ", " }}'
+ type="{{ .default.MediaType }}"
+ >
+
+ <img
+ {{ with $class }}class="{{ . }}"{{ end }}
+ loading="lazy"
+ {{ with .default }}
+ src="{{ .RelPermalink }}"
+ width="{{ .Width }}"
+ height="{{ .Height }}"
+ {{ end }}
+ {{ with $altText }}alt="{{ . }}"{{ end }}
+ />
+
+ </picture>
- <img
- {{ with $class }}class="{{ . }}"{{ end }}
- loading="lazy"
- srcset='{{ delimit $outputSet ", " }}'
- src="{{ (.Resize $mediumRes).RelPermalink }}"
- width="{{ (.Resize $mediumRes).Width }}"
- height="{{ (.Resize $mediumRes).Height }}"
- {{ with $altText }}alt="{{ . }}"{{ end }}
- />
-
{{ else }}
-
- {{ $processed := (.Resize (printf "%vx" .Width)) }}
-
- <img
- {{ with $class }}class="{{ . }}"{{ end }}
- loading="lazy"
- src="{{ $processed.RelPermalink }}"
- width="{{ .Width }}"
- height="{{ .Height }}"
- {{ with $altText }}alt="{{ . }}"{{ end }}
- />
-
- {{ end }}
+
+ <!-- Avoid trying to get width and height from SVG files -->
+ {{ if .input }}
+ <img
+ {{ with $class }}class="{{ . }}"{{ end }}
+ loading="lazy"
+ {{ with .input }}
+ src="{{ .RelPermalink }}"
+ {{ if ne .MediaType.SubType "svg" }}
+ width="{{ .Width }}"
+ height="{{ .Height }}"
+ {{ end }}
+ {{ end }}
+ {{ with $altText }}alt="{{ . }}"{{ end }}
+ />
+ {{ else }}
+
+ <!-- If local file isn't found, assume it's a remote file -->
+ {{ with ($.Destination | safeURL) }}
+ <img
+ {{ with $class }}class="{{ . }}"{{ end }}
+ loading="lazy"
+ src="{{ . }}"
+ {{ with $altText }}alt="{{ . }}"{{ end }}
+ />
+ {{ end }}
+ {{ end }}
-{{ else }}
- <!-- If local file isn't found, assume it's a remote file -->
- {{ with (.Destination | safeURL) }}
-
- <img
- {{ with $class }}class="{{ . }}"{{ end }}
- loading="lazy"
- src="{{ . }}"
- {{ with $altText }}alt="{{ . }}"{{ end }}
- />
-
{{ end }}
+
{{ end }}