From 2bb7687a34f3e3af9aff885de67b29216ff0751f Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Sun, 27 Mar 2022 19:55:28 +0530 Subject: [PATCH] Profile-Mode: 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 `profileMode.imageUrl`. - if image is located as `assets/images/image.png` mention `profileMode.imageUrl: images/image.png`. --- layouts/partials/index_profile.html | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/layouts/partials/index_profile.html b/layouts/partials/index_profile.html index 3851e715..1bb2079f 100644 --- a/layouts/partials/index_profile.html +++ b/layouts/partials/index_profile.html @@ -2,9 +2,31 @@ {{- with site.Params.profileMode }}
{{- if .imageUrl -}} + {{- $img := resources.Get .imageUrl }} + {{- 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")) }} + {{- if and (in $processableFormats $img.MediaType.SubType) (eq $prod true)}} + {{- if (not (and (not .imageHeight) (not .imageWidth))) }} + {{- $img = $img.Resize (printf "%dx%d" .imageWidth .imageHeight) }} + {{- else if .imageHeight }} + {{- $img = $img.Resize (printf "x%d" .imageHeight) }} + {{ else if .imageWidth }} + {{- $img = $img.Resize (printf "%dx" .imageWidth) }} + {{ else }} + {{- $img = $img.Resize "150x150" }} + {{- end }} + {{- end }} + {{ .imageTitle | default + {{- else }} {{ .imageTitle | default {{- end }} + {{- end }}

{{ .title | default site.Title | markdownify }}

{{ .subtitle | markdownify }} {{- partial "social_icons.html" site.Params.socialIcons -}} @@ -20,4 +42,4 @@ {{- end }}
{{- end}} - + \ No newline at end of file