Skip to content

Commit 0a81a6b

Browse files
committed
output: Fall back to unstranslated base template
Fixes #3893
1 parent 60dfb9a commit 0a81a6b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

‎output/layout_base.go‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
174174
// Also note that the <current-path> may be both the project's layout folder and the theme's.
175175
pairsToCheck := createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)
176176

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)...)
177+
// We may have language code and/or "terms" in the template name. We want the most specific,
178+
// but need to fall back to the baseof.html or baseof.ace if needed.
179+
// E.g. list-baseof.en.html and list-baseof.terms.en.html
180+
// See #3893, #3856.
181+
baseBaseFilename, currBaseBaseFilename := helpers.Filename(baseFilename), helpers.Filename(currBaseFilename)
182+
p1, p2 := strings.Split(baseBaseFilename, "."), strings.Split(currBaseBaseFilename, ".")
183+
if len(p1) > 0 && len(p1) == len(p2) {
184+
for i := len(p1); i > 0; i-- {
185+
v1, v2 := strings.Join(p1[:i], ".")+"."+ext, strings.Join(p2[:i], ".")+"."+ext
186+
pairsToCheck = append(pairsToCheck, createPairsToCheck(baseTemplatedDir, v1, v2)...)
187+
188+
}
183189
}
184190

185191
Loop:

‎output/layout_base_test.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ 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 #3893
54+
{"Base Lang, Default Base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: "layouts", RelPath: "_default/list.en.html"}, true, "_default/baseof.html",
55+
TemplateNames{
56+
Name: "_default/list.en.html",
57+
OverlayFilename: "/sites/mysite/layouts/_default/list.en.html",
58+
MasterFilename: "/sites/mysite/layouts/_default/baseof.html",
59+
}},
60+
{"Base Lang, Lang Base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: "layouts", RelPath: "_default/list.en.html"}, true, "_default/baseof.html|_default/baseof.en.html",
61+
TemplateNames{
62+
Name: "_default/list.en.html",
63+
OverlayFilename: "/sites/mysite/layouts/_default/list.en.html",
64+
MasterFilename: "/sites/mysite/layouts/_default/baseof.en.html",
65+
}},
5366
// Issue #3856
5467
{"Base Taxonomy Term", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: "taxonomy/tag.terms.html"}, true, "_default/baseof.html",
5568
TemplateNames{
@@ -116,12 +129,11 @@ func TestLayoutBase(t *testing.T) {
116129
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
117130
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.amp.html",
118131
}},
119-
{"AMP with no match in base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathAmp}, true, "single-baseof.html",
132+
{"AMP with no AMP base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathAmp}, true, "single-baseof.html",
120133
TemplateNames{
121134
Name: "_default/single.amp.html",
122135
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
123-
// There is a single-baseof.html, but that makes no sense.
124-
MasterFilename: "",
136+
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html",
125137
}},
126138

127139
{"JSON with base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathJSON}, true, "single-baseof.json",

0 commit comments

Comments
 (0)