mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
tpl/tplimpl: Retain query string and fragment in render-image.html
Closes #12468
This commit is contained in:
parent
ca9a77ef92
commit
6dfeb9f038
2 changed files with 17 additions and 7 deletions
|
@ -3,6 +3,12 @@
|
||||||
{{- if not $u.IsAbs -}}
|
{{- if not $u.IsAbs -}}
|
||||||
{{- with or (.PageInner.Resources.Get $u.Path) (resources.Get $u.Path) -}}
|
{{- with or (.PageInner.Resources.Get $u.Path) (resources.Get $u.Path) -}}
|
||||||
{{- $src = .RelPermalink -}}
|
{{- $src = .RelPermalink -}}
|
||||||
|
{{- with $u.RawQuery -}}
|
||||||
|
{{- $src = printf "%s?%s" $src . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $u.Fragment -}}
|
||||||
|
{{- $src = printf "%s#%s" $src . -}}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape)) -}}
|
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape)) -}}
|
||||||
|
|
|
@ -130,30 +130,34 @@ title: s1/p3
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue 12203
|
// Issue 12203
|
||||||
func TestEmbeddedImageRenderHookMarkdownAttributes(t *testing.T) {
|
// Issue 12468
|
||||||
|
func TestEmbeddedImageRenderHook(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
files := `
|
files := `
|
||||||
-- config.toml --
|
-- config.toml --
|
||||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
baseURL = 'https://example.org/dir/'
|
||||||
|
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
|
||||||
[markup.goldmark.parser]
|
[markup.goldmark.parser]
|
||||||
wrapStandAloneImageWithinParagraph = false
|
wrapStandAloneImageWithinParagraph = false
|
||||||
[markup.goldmark.parser.attribute]
|
[markup.goldmark.parser.attribute]
|
||||||
block = false
|
block = false
|
||||||
[markup.goldmark.renderHooks.image]
|
[markup.goldmark.renderHooks.image]
|
||||||
enableDefault = true
|
enableDefault = true
|
||||||
-- content/_index.md --
|
-- content/p1/index.md --
|
||||||
![alt](a.jpg)
|
![alt](pixel.png?a=b&c=d#fragment)
|
||||||
{.foo #bar}
|
{.foo #bar}
|
||||||
-- layouts/index.html --
|
-- content/p1/pixel.png --
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||||
|
-- layouts/_default/single.html --
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
`
|
`
|
||||||
|
|
||||||
b := hugolib.Test(t, files)
|
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)
|
files = strings.Replace(files, "block = false", "block = true", -1)
|
||||||
|
|
||||||
b = hugolib.Test(t, files)
|
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…
Reference in a new issue