From 7f778f78ea74003c3af558a547bee645bbdb037d Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:02:44 +0200 Subject: [PATCH] hugo: use URL parser for image ref in render hook Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- layouts/_default/_markup/render-image.html | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index d41c920b11..c1b6449865 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,13 +1,14 @@ -{{ $imagePath := .Destination }} -{{ if and (eq .Page.Kind "page") (not (hasPrefix .Destination "/")) }} - {{ $imagePath = (printf "../%s" .Destination) }} +{{- $u := urls.Parse .Destination -}} +{{- $src := $u.String -}} +{{ if not (or $u.IsAbs (strings.HasPrefix $u.String "/")) }} + {{ $base := urls.Parse .Page.Permalink }} + {{ $src = $base.JoinPath "../" $u.Path -}} {{ end }} -{{ $params := (urls.Parse $imagePath).Query }} -{{ $width := index $params "w" }} -{{ $height := index $params "h" }} -{{ $border := index $params "border" }} - +{{ $params := $u.Query }} +{{ $width := $params.Get "w" }} +{{ $height := $params.Get "h" }} +{{ $border := $params.Has "border" }}
{{ .Text }} {{ with .Title }} @@ -45,9 +41,8 @@ {{ .Text }}