Skip to content

Commit f88fe31

Browse files
committed
output: Fix taxonomy term base template lookup
To make sure it uses the base templates in _default as a last resort. Fixes #3856
1 parent d33563b commit f88fe31

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

‎output/layout_base.go‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"github.com/gohugoio/hugo/helpers"
2222
)
2323

24-
const baseFileBase = "baseof"
24+
const (
25+
baseFileBase = "baseof"
26+
)
2527

2628
var (
2729
aceTemplateInnerMarkers = [][]byte{[]byte("= content")}
@@ -170,11 +172,14 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
170172
// For each of the steps above, it will first look in the project, then, if theme is set,
171173
// in the theme's layouts folder.
172174
// Also note that the <current-path> may be both the project's layout folder and the theme's.
173-
pairsToCheck := [][]string{
174-
{baseTemplatedDir, currBaseFilename},
175-
{baseTemplatedDir, baseFilename},
176-
{"_default", currBaseFilename},
177-
{"_default", baseFilename},
175+
pairsToCheck := createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)
176+
177+
if strings.Contains(currBaseFilename, ".terms.") {
178+
// We need to get from baseof.terms.html to baseof.html etc.
179+
// See #3856
180+
currBaseFilename = strings.Replace(currBaseFilename, ".terms", "", 1)
181+
baseFilename = strings.Replace(baseFilename, ".terms", "", 1)
182+
pairsToCheck = append(pairsToCheck, createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)...)
178183
}
179184

180185
Loop:
@@ -194,6 +199,15 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
194199

195200
}
196201

202+
func createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename string) [][]string {
203+
return [][]string{
204+
{baseTemplatedDir, currBaseFilename},
205+
{baseTemplatedDir, baseFilename},
206+
{"_default", currBaseFilename},
207+
{"_default", baseFilename},
208+
}
209+
}
210+
197211
func basePathsToCheck(path []string, layoutDir, workLayoutDir, themeLayoutDir string) []string {
198212
// workLayoutDir will always be the most specific, so start there.
199213
pathsToCheck := []string{filepath.Join((append([]string{workLayoutDir}, path...))...)}

‎output/layout_base_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ func TestLayoutBase(t *testing.T) {
5050
OverlayFilename: "/sites/mysite/layouts/_default/single.html",
5151
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html",
5252
}},
53+
// Issue #3856
54+
{"Base Taxonomy Term", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: "taxonomy/tag.terms.html"}, true, "_default/baseof.html",
55+
TemplateNames{
56+
Name: "taxonomy/tag.terms.html",
57+
OverlayFilename: "/sites/mysite/layouts/taxonomy/tag.terms.html",
58+
MasterFilename: "/sites/mysite/layouts/_default/baseof.html",
59+
}},
60+
5361
{"Base in theme", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPath1, ThemeDir: themeDir}, true,
5462
"mytheme/layouts/_default/baseof.html",
5563
TemplateNames{

0 commit comments

Comments
 (0)