Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tpl/tplimpl: Retain query string and fragment in render-image.html #12469

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) -}}
Expand Down
18 changes: 11 additions & 7 deletions tpl/tplimpl/render_hook_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", `<img alt="alt" src="a.jpg">`)
b.AssertFileContent("public/p1/index.html", `<img alt="alt" src="/dir/p1/pixel.png?a=b&c=d#fragment">`)

files = strings.Replace(files, "block = false", "block = true", -1)

b = hugolib.Test(t, files)
b.AssertFileContent("public/index.html", `<img alt="alt" class="foo" id="bar" src="a.jpg">`)
b.AssertFileContent("public/p1/index.html", `<img alt="alt" class="foo" id="bar" src="/dir/p1/pixel.png?a=b&c=d#fragment">`)
}
Loading