From 1de55c426639e6320f171d63a6c548e69c011f93 Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Sun, 27 Mar 2022 20:17:49 +0530 Subject: [PATCH] Label.logo: Generate a resize image if the image is present in assets directory. - Resizing the image will reduce the size of a large image. - Should improve image load time. - Usage: - Add the image under assets directory. - Provide path in `label.icon`. - if image is located as `assets/images/image.png` mention `label.icon: images/image.png`. --- layouts/partials/header.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/layouts/partials/header.html b/layouts/partials/header.html index ff674c52..55139a29 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -46,9 +46,31 @@ {{- if site.Title }} {{- if site.Params.label.icon }} + {{- $img := resources.Get site.Params.label.icon }} + {{- if $img }} + {{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}} + {{- if hugo.IsExtended -}} + {{- $processableFormats = $processableFormats | append "webp" -}} + {{- end -}} + {{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }} + {{- $imgUrl := "" }} + {{- if and (in $processableFormats $img.MediaType.SubType) (eq $prod true)}} + {{- if site.Params.label.iconHeight }} + {{- $img = $img.Resize (printf "x%d" site.Params.label.iconHeight) }} + {{ else }} + {{- $img = $img.Resize "x30" }} + {{- end }} + {{- $imgUrl = $img.Permalink }} + {{- else }} + {{- $imgUrl = site.Params.label.icon | absURL }} + {{- end }} + logo + {{- else }} logo {{- end -}} + {{- end -}} {{- $label_text -}} {{- end }}