diff options
author | Raphael Aguiar <rmaguiar@tuta.io> | 2022-06-04 07:51:52 +0300 |
---|---|---|
committer | Raphael Aguiar <rmaguiar@tuta.io> | 2022-06-04 07:52:09 +0300 |
commit | 4cb78fa1eb001ad64343a2795218b3ab37b559a8 (patch) | |
tree | 0f99436eee9d736e460a81e15896755d98f618d9 /layouts/_default/_markup/render-image.html | |
parent | b767c4e39893384d6821e357ba6d4c901a5eb9b7 (diff) |
Overhaul image processing and other changes
* Get rid of every single `.Scratch`
* Bump KaTeX from 0.15.3 to 0.15.6
* Bump Fuse from 6.5.3 to 6.6.2
* Add cache busting to search indexes
* Improve search results in general
* Overhaul image processing
* By default, use `webp` as an extra image format conditionally (Hugo 0.83+)
* Other minor changes
Diffstat (limited to 'layouts/_default/_markup/render-image.html')
-rw-r--r-- | layouts/_default/_markup/render-image.html | 113 |
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 }} |