diff --git a/tpl/tplimpl/templatestore.go b/tpl/tplimpl/templatestore.go index 0c03b2cc186..0f9dc6841ca 100644 --- a/tpl/tplimpl/templatestore.go +++ b/tpl/tplimpl/templatestore.go @@ -1212,6 +1212,12 @@ func (s *TemplateStore) insertTemplate2( replace = subCategory == SubCategoryInline && nkExisting.subCategory == SubCategoryInline } + if !replace && existingFound && fi != nil && nkExisting.Fi != nil { + // Fix issue #13877. + primarySuffix := s.htmlFormat.MediaType.FirstSuffix.FullSuffix + replace = strings.HasSuffix(fi.Name(), primarySuffix) && !strings.HasSuffix(nkExisting.Fi.Name(), primarySuffix) + } + 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. diff --git a/tpl/tplimpl/templatestore_test.go b/tpl/tplimpl/templatestore_test.go new file mode 100644 index 00000000000..9cf44199533 --- /dev/null +++ b/tpl/tplimpl/templatestore_test.go @@ -0,0 +1,38 @@ +package tplimpl_test + +import ( + "testing" + + "github.com/gohugoio/hugo/hugolib" +) + +func TestIssue13877(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] + +[mediaTypes.'text/html'] +suffixes = ['b','a','d','c'] + +[outputFormats.html] +mediaType = 'text/html' +-- content/p1.md -- +--- +title: p1 +--- +-- layouts/page.html.a -- +{{ templates.Current.Name }} +-- layouts/page.html.b -- +{{ templates.Current.Name }} +-- layouts/page.html.c -- +{{ templates.Current.Name }} +-- layouts/page.html.d -- +{{ templates.Current.Name }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.b", "page.html.b") +}