mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-08 19:36:36 +02:00
tpl: Fix theme overrides when theme has old layout setup (e.g. _default)
Fixes #13715
This commit is contained in:
@@ -1133,12 +1133,21 @@ func (s *TemplateStore) insertTemplate2(
|
|||||||
tree.Insert(key, m)
|
tree.Insert(key, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !replace {
|
nkExisting, existingFound := m[nk]
|
||||||
if v, found := m[nk]; found {
|
if !replace && existingFound && fi != nil && nkExisting.Fi != nil {
|
||||||
if len(pi.Identifiers()) >= len(v.PathInfo.Identifiers()) {
|
// See issue #13715.
|
||||||
// e.g. /pages/home.foo.html and /pages/home.html where foo may be a valid language name in another site.
|
// We do the merge on the file system level, but from Hugo v0.146.0 we have a situation where
|
||||||
return nil, nil
|
// the project may well have a different layouts layout compared to the theme(s) it uses.
|
||||||
}
|
// We could possibly have fixed that on a lower (file system) level, but since this is just
|
||||||
|
// a temporary situation (until all projects are updated),
|
||||||
|
// do a replace here if the file comes from higher up in the module chain.
|
||||||
|
replace = fi.Meta().ModuleOrdinal < nkExisting.Fi.Meta().ModuleOrdinal
|
||||||
|
}
|
||||||
|
|
||||||
|
if !replace && existingFound {
|
||||||
|
if len(pi.Identifiers()) >= len(nkExisting.PathInfo.Identifiers()) {
|
||||||
|
// e.g. /pages/home.foo.html and /pages/home.html where foo may be a valid language name in another site.
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1103,6 +1103,23 @@ All.
|
|||||||
b.AssertLogContains("unrecognized render hook")
|
b.AssertLogContains("unrecognized render hook")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLayoutOverrideThemeWhenThemeOnOldFormatIssue13715(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
theme = "mytheme"
|
||||||
|
-- layouts/list.html --
|
||||||
|
layouts/list.html
|
||||||
|
-- themes/mytheme/layouts/_default/list.html --
|
||||||
|
mytheme/layouts/_default/list.html
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
b.AssertFileContent("public/index.html", "layouts/list.html")
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkExecuteWithContext(b *testing.B) {
|
func BenchmarkExecuteWithContext(b *testing.B) {
|
||||||
files := `
|
files := `
|
||||||
-- hugo.toml --
|
-- hugo.toml --
|
||||||
|
Reference in New Issue
Block a user