diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-09-03 11:32:26 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-09-03 11:32:26 +0200 |
commit | f88fe312cb35f7de1615c095edd2f898303dd23b (patch) | |
tree | 9bd3c24405aac13ad7b728d931cf2763a75dcea7 | |
parent | d33563b5d79af01260a24cea355160d802b2bd4e (diff) | |
download | hugo-f88fe312cb35f7de1615c095edd2f898303dd23b.tar.gz hugo-f88fe312cb35f7de1615c095edd2f898303dd23b.zip |
output: Fix taxonomy term base template lookup
To make sure it uses the base templates in _default as a last resort.
Fixes #3856
-rw-r--r-- | output/layout_base.go | 26 | ||||
-rw-r--r-- | output/layout_base_test.go | 8 |
2 files changed, 28 insertions, 6 deletions
diff --git a/output/layout_base.go b/output/layout_base.go index dc653ad0f..79baf9b5f 100644 --- a/output/layout_base.go +++ b/output/layout_base.go @@ -21,7 +21,9 @@ import ( "github.com/gohugoio/hugo/helpers" ) -const baseFileBase = "baseof" +const ( + baseFileBase = "baseof" +) var ( aceTemplateInnerMarkers = [][]byte{[]byte("= content")} @@ -170,11 +172,14 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) { // For each of the steps above, it will first look in the project, then, if theme is set, // in the theme's layouts folder. // Also note that the <current-path> may be both the project's layout folder and the theme's. - pairsToCheck := [][]string{ - {baseTemplatedDir, currBaseFilename}, - {baseTemplatedDir, baseFilename}, - {"_default", currBaseFilename}, - {"_default", baseFilename}, + pairsToCheck := createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename) + + if strings.Contains(currBaseFilename, ".terms.") { + // We need to get from baseof.terms.html to baseof.html etc. + // See #3856 + currBaseFilename = strings.Replace(currBaseFilename, ".terms", "", 1) + baseFilename = strings.Replace(baseFilename, ".terms", "", 1) + pairsToCheck = append(pairsToCheck, createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)...) } Loop: @@ -194,6 +199,15 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) { } +func createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename string) [][]string { + return [][]string{ + {baseTemplatedDir, currBaseFilename}, + {baseTemplatedDir, baseFilename}, + {"_default", currBaseFilename}, + {"_default", baseFilename}, + } +} + func basePathsToCheck(path []string, layoutDir, workLayoutDir, themeLayoutDir string) []string { // workLayoutDir will always be the most specific, so start there. pathsToCheck := []string{filepath.Join((append([]string{workLayoutDir}, path...))...)} diff --git a/output/layout_base_test.go b/output/layout_base_test.go index b78f31352..2435fed03 100644 --- a/output/layout_base_test.go +++ b/output/layout_base_test.go @@ -50,6 +50,14 @@ func TestLayoutBase(t *testing.T) { OverlayFilename: "/sites/mysite/layouts/_default/single.html", MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html", }}, + // Issue #3856 + {"Base Taxonomy Term", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: "taxonomy/tag.terms.html"}, true, "_default/baseof.html", + TemplateNames{ + Name: "taxonomy/tag.terms.html", + OverlayFilename: "/sites/mysite/layouts/taxonomy/tag.terms.html", + MasterFilename: "/sites/mysite/layouts/_default/baseof.html", + }}, + {"Base in theme", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPath1, ThemeDir: themeDir}, true, "mytheme/layouts/_default/baseof.html", TemplateNames{ |