mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-04 16:21:57 +00:00
hugolib: Fix error for non-renderable HTML content with shortcodes
This commit re-introduces template lookup order that was accidently removed as part of the template nonglobal refactoring. Fixes #3021
This commit is contained in:
parent
25bfa7e12f
commit
2618cfbeaa
|
@ -436,6 +436,8 @@ func TestSkipRender(t *testing.T) {
|
||||||
{Name: filepath.FromSlash("sect/doc6.html"), Content: []byte("<!doctype html><html>{{ template \"head_abs\" }}<body>body5</body></html>")},
|
{Name: filepath.FromSlash("sect/doc6.html"), Content: []byte("<!doctype html><html>{{ template \"head_abs\" }}<body>body5</body></html>")},
|
||||||
{Name: filepath.FromSlash("doc7.html"), Content: []byte("<html><body>doc7 content</body></html>")},
|
{Name: filepath.FromSlash("doc7.html"), Content: []byte("<html><body>doc7 content</body></html>")},
|
||||||
{Name: filepath.FromSlash("sect/doc8.html"), Content: []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
|
{Name: filepath.FromSlash("sect/doc8.html"), Content: []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
|
||||||
|
// Issue #3021
|
||||||
|
{Name: filepath.FromSlash("doc9.html"), Content: []byte("<html><body>doc9: {{< myshortcode >}}</body></html>")},
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.Set("defaultExtension", "html")
|
viper.Set("defaultExtension", "html")
|
||||||
|
@ -454,6 +456,7 @@ func TestSkipRender(t *testing.T) {
|
||||||
writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}")
|
writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}")
|
||||||
writeSource(t, fs, filepath.Join("layouts", "head"), "<head><script src=\"script.js\"></script></head>")
|
writeSource(t, fs, filepath.Join("layouts", "head"), "<head><script src=\"script.js\"></script></head>")
|
||||||
writeSource(t, fs, filepath.Join("layouts", "head_abs"), "<head><script src=\"/script.js\"></script></head>")
|
writeSource(t, fs, filepath.Join("layouts", "head_abs"), "<head><script src=\"/script.js\"></script></head>")
|
||||||
|
writeSource(t, fs, filepath.Join("layouts", "shortcodes", "myshortcode.html"), "SHORT")
|
||||||
|
|
||||||
buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{})
|
buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{})
|
||||||
|
|
||||||
|
@ -469,6 +472,7 @@ func TestSkipRender(t *testing.T) {
|
||||||
{filepath.FromSlash("public/sect/doc6.html"), "<!doctype html><html><head><script src=\"http://auth/bub/script.js\"></script></head><body>body5</body></html>"},
|
{filepath.FromSlash("public/sect/doc6.html"), "<!doctype html><html><head><script src=\"http://auth/bub/script.js\"></script></head><body>body5</body></html>"},
|
||||||
{filepath.FromSlash("public/doc7.html"), "<html><body>doc7 content</body></html>"},
|
{filepath.FromSlash("public/doc7.html"), "<html><body>doc7 content</body></html>"},
|
||||||
{filepath.FromSlash("public/sect/doc8.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
|
{filepath.FromSlash("public/sect/doc8.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
|
||||||
|
{filepath.FromSlash("public/doc9.html"), "<html><body>doc9: SHORT</body></html>"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
@ -141,7 +141,6 @@ func (t *GoHTMLTemplate) initFuncs(d *deps.Deps) {
|
||||||
// Hacky, but we need to make sure that the func names are in the global map.
|
// Hacky, but we need to make sure that the func names are in the global map.
|
||||||
amber.FuncMap[k] = func() string {
|
amber.FuncMap[k] = func() string {
|
||||||
panic("should never be invoked")
|
panic("should never be invoked")
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,12 +196,18 @@ func (t *GoHTMLTemplate) ExecuteTemplateToHTML(context interface{}, layouts ...s
|
||||||
|
|
||||||
func (t *GoHTMLTemplate) Lookup(name string) *template.Template {
|
func (t *GoHTMLTemplate) Lookup(name string) *template.Template {
|
||||||
|
|
||||||
|
if templ := t.Template.Lookup(name); templ != nil {
|
||||||
|
return templ
|
||||||
|
}
|
||||||
|
|
||||||
if t.overlays != nil {
|
if t.overlays != nil {
|
||||||
if templ, ok := t.overlays[name]; ok {
|
if templ, ok := t.overlays[name]; ok {
|
||||||
return templ
|
return templ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The clone is used for the non-renderable HTML pages (p.IsRenderable == false) that is parsed
|
||||||
|
// as Go templates late in the build process.
|
||||||
if t.clone != nil {
|
if t.clone != nil {
|
||||||
if templ := t.clone.Lookup(name); templ != nil {
|
if templ := t.clone.Lookup(name); templ != nil {
|
||||||
return templ
|
return templ
|
||||||
|
|
Loading…
Reference in a new issue