From 6dfeb9f0388f5acae2c8f2e16d97987899a04d4e Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Tue, 7 May 2024 10:12:19 -0700 Subject: [PATCH] tpl/tplimpl: Retain query string and fragment in render-image.html Closes #12468 --- .../_default/_markup/render-image.html | 6 ++++++ tpl/tplimpl/render_hook_integration_test.go | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html b/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html index 875763910..31437cdd4 100644 --- a/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html +++ b/tpl/tplimpl/embedded/templates/_default/_markup/render-image.html @@ -3,6 +3,12 @@ {{- if not $u.IsAbs -}} {{- with or (.PageInner.Resources.Get $u.Path) (resources.Get $u.Path) -}} {{- $src = .RelPermalink -}} + {{- with $u.RawQuery -}} + {{- $src = printf "%s?%s" $src . -}} + {{- end -}} + {{- with $u.Fragment -}} + {{- $src = printf "%s#%s" $src . -}} + {{- end -}} {{- end -}} {{- end -}} {{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape)) -}} diff --git a/tpl/tplimpl/render_hook_integration_test.go b/tpl/tplimpl/render_hook_integration_test.go index 07c24108d..f6cb5bf6b 100644 --- a/tpl/tplimpl/render_hook_integration_test.go +++ b/tpl/tplimpl/render_hook_integration_test.go @@ -130,30 +130,34 @@ title: s1/p3 } // Issue 12203 -func TestEmbeddedImageRenderHookMarkdownAttributes(t *testing.T) { +// Issue 12468 +func TestEmbeddedImageRenderHook(t *testing.T) { t.Parallel() files := ` -- config.toml -- -disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +baseURL = 'https://example.org/dir/' +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] [markup.goldmark.parser] wrapStandAloneImageWithinParagraph = false [markup.goldmark.parser.attribute] block = false [markup.goldmark.renderHooks.image] enableDefault = true --- content/_index.md -- -![alt](a.jpg) +-- content/p1/index.md -- +![alt](pixel.png?a=b&c=d#fragment) {.foo #bar} --- layouts/index.html -- +-- content/p1/pixel.png -- +iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg== +-- layouts/_default/single.html -- {{ .Content }} ` b := hugolib.Test(t, files) - b.AssertFileContent("public/index.html", `alt`) + b.AssertFileContent("public/p1/index.html", `alt`) files = strings.Replace(files, "block = false", "block = true", -1) b = hugolib.Test(t, files) - b.AssertFileContent("public/index.html", `alt`) + b.AssertFileContent("public/p1/index.html", `alt`) }