Skip to content

Commit b893a09

Browse files
jmooringbep
authored andcommitted
tpl/tplimpl: Resolve render hook destinations with leading ./
Closes gohugoio#12514
1 parent 6b00661 commit b893a09

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

‎tpl/tplimpl/embedded/templates/_default/_markup/render-image.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{{- $u := urls.Parse .Destination -}}
22
{{- $src := $u.String -}}
33
{{- if not $u.IsAbs -}}
4-
{{- with or (.PageInner.Resources.Get $u.Path) (resources.Get $u.Path) -}}
4+
{{- $path := strings.TrimPrefix "./" $u.Path }}
5+
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
56
{{- $src = .RelPermalink -}}
67
{{- with $u.RawQuery -}}
78
{{- $src = printf "%s?%s" $src . -}}

‎tpl/tplimpl/embedded/templates/_default/_markup/render-link.html‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
{{- if strings.HasPrefix $u.String "#" }}
44
{{- $href = printf "%s#%s" .PageInner.RelPermalink $u.Fragment }}
55
{{- else if not $u.IsAbs -}}
6+
{{- $path := strings.TrimPrefix "./" $u.Path }}
67
{{- with or
7-
($.PageInner.GetPage $u.Path)
8-
($.PageInner.Resources.Get $u.Path)
9-
(resources.Get $u.Path)
8+
($.PageInner.GetPage $path)
9+
($.PageInner.Resources.Get $path)
10+
(resources.Get $path)
1011
-}}
1112
{{- $href = .RelPermalink -}}
1213
{{- with $u.RawQuery -}}

‎tpl/tplimpl/render_hook_integration_test.go‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ title: s1/p1
5151
title: s1/p2
5252
---
5353
[500](a.txt) // global resource
54-
[600](b.txt) // page resource
54+
[510](b.txt) // page resource
55+
[520](./b.txt) // page resource
5556
-- content/s1/p2/b.txt --
5657
irrelevant
5758
-- content/s1/p3.md --
@@ -125,12 +126,14 @@ title: s1/p3
125126

126127
b.AssertFileContent("public/s1/p2/index.html",
127128
`<a href="/a.txt">500</a>`,
128-
`<a href="/s1/p2/b.txt">600</a>`,
129+
`<a href="/s1/p2/b.txt">510</a>`,
130+
`<a href="/s1/p2/b.txt">520</a>`,
129131
)
130132
}
131133

132134
// Issue 12203
133135
// Issue 12468
136+
// Issue 12514
134137
func TestEmbeddedImageRenderHook(t *testing.T) {
135138
t.Parallel()
136139

@@ -145,7 +148,9 @@ block = false
145148
[markup.goldmark.renderHooks.image]
146149
enableDefault = true
147150
-- content/p1/index.md --
148-
![alt](pixel.png?a=b&c=d#fragment)
151+
![alt1](./pixel.png)
152+
153+
![alt2](pixel.png?a=b&c=d#fragment)
149154
{.foo #bar}
150155
-- content/p1/pixel.png --
151156
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
@@ -154,10 +159,16 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA
154159
`
155160

156161
b := hugolib.Test(t, files)
157-
b.AssertFileContent("public/p1/index.html", `<img alt="alt" src="/dir/p1/pixel.png?a=b&c=d#fragment">`)
162+
b.AssertFileContent("public/p1/index.html",
163+
`<img alt="alt1" src="/dir/p1/pixel.png">`,
164+
`<img alt="alt2" src="/dir/p1/pixel.png?a=b&c=d#fragment">`,
165+
)
158166

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

161169
b = hugolib.Test(t, files)
162-
b.AssertFileContent("public/p1/index.html", `<img alt="alt" class="foo" id="bar" src="/dir/p1/pixel.png?a=b&c=d#fragment">`)
170+
b.AssertFileContent("public/p1/index.html",
171+
`<img alt="alt1" src="/dir/p1/pixel.png">`,
172+
`<img alt="alt2" class="foo" id="bar" src="/dir/p1/pixel.png?a=b&c=d#fragment">`,
173+
)
163174
}

0 commit comments

Comments
 (0)