mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
60dfb9a6e0
commit
0a81a6b4ba
2 changed files with 27 additions and 9 deletions
|
@ -174,12 +174,18 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
|
||||||
// Also note that the <current-path> may be both the project's layout folder and the theme's.
|
// Also note that the <current-path> may be both the project's layout folder and the theme's.
|
||||||
pairsToCheck := createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)
|
pairsToCheck := createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)
|
||||||
|
|
||||||
if strings.Contains(currBaseFilename, ".terms.") {
|
// We may have language code and/or "terms" in the template name. We want the most specific,
|
||||||
// We need to get from baseof.terms.html to baseof.html etc.
|
// but need to fall back to the baseof.html or baseof.ace if needed.
|
||||||
// See #3856
|
// E.g. list-baseof.en.html and list-baseof.terms.en.html
|
||||||
currBaseFilename = strings.Replace(currBaseFilename, ".terms", "", 1)
|
// See #3893, #3856.
|
||||||
baseFilename = strings.Replace(baseFilename, ".terms", "", 1)
|
baseBaseFilename, currBaseBaseFilename := helpers.Filename(baseFilename), helpers.Filename(currBaseFilename)
|
||||||
pairsToCheck = append(pairsToCheck, createPairsToCheck(baseTemplatedDir, baseFilename, currBaseFilename)...)
|
p1, p2 := strings.Split(baseBaseFilename, "."), strings.Split(currBaseBaseFilename, ".")
|
||||||
|
if len(p1) > 0 && len(p1) == len(p2) {
|
||||||
|
for i := len(p1); i > 0; i-- {
|
||||||
|
v1, v2 := strings.Join(p1[:i], ".")+"."+ext, strings.Join(p2[:i], ".")+"."+ext
|
||||||
|
pairsToCheck = append(pairsToCheck, createPairsToCheck(baseTemplatedDir, v1, v2)...)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
|
|
|
@ -50,6 +50,19 @@ func TestLayoutBase(t *testing.T) {
|
||||||
OverlayFilename: "/sites/mysite/layouts/_default/single.html",
|
OverlayFilename: "/sites/mysite/layouts/_default/single.html",
|
||||||
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html",
|
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html",
|
||||||
}},
|
}},
|
||||||
|
// Issue #3893
|
||||||
|
{"Base Lang, Default Base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: "layouts", RelPath: "_default/list.en.html"}, true, "_default/baseof.html",
|
||||||
|
TemplateNames{
|
||||||
|
Name: "_default/list.en.html",
|
||||||
|
OverlayFilename: "/sites/mysite/layouts/_default/list.en.html",
|
||||||
|
MasterFilename: "/sites/mysite/layouts/_default/baseof.html",
|
||||||
|
}},
|
||||||
|
{"Base Lang, Lang Base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: "layouts", RelPath: "_default/list.en.html"}, true, "_default/baseof.html|_default/baseof.en.html",
|
||||||
|
TemplateNames{
|
||||||
|
Name: "_default/list.en.html",
|
||||||
|
OverlayFilename: "/sites/mysite/layouts/_default/list.en.html",
|
||||||
|
MasterFilename: "/sites/mysite/layouts/_default/baseof.en.html",
|
||||||
|
}},
|
||||||
// Issue #3856
|
// Issue #3856
|
||||||
{"Base Taxonomy Term", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: "taxonomy/tag.terms.html"}, true, "_default/baseof.html",
|
{"Base Taxonomy Term", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: "taxonomy/tag.terms.html"}, true, "_default/baseof.html",
|
||||||
TemplateNames{
|
TemplateNames{
|
||||||
|
@ -116,12 +129,11 @@ func TestLayoutBase(t *testing.T) {
|
||||||
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
|
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
|
||||||
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.amp.html",
|
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.amp.html",
|
||||||
}},
|
}},
|
||||||
{"AMP with no match in base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathAmp}, true, "single-baseof.html",
|
{"AMP with no AMP base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathAmp}, true, "single-baseof.html",
|
||||||
TemplateNames{
|
TemplateNames{
|
||||||
Name: "_default/single.amp.html",
|
Name: "_default/single.amp.html",
|
||||||
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
|
OverlayFilename: "/sites/mysite/layouts/_default/single.amp.html",
|
||||||
// There is a single-baseof.html, but that makes no sense.
|
MasterFilename: "/sites/mysite/layouts/_default/single-baseof.html",
|
||||||
MasterFilename: "",
|
|
||||||
}},
|
}},
|
||||||
|
|
||||||
{"JSON with base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathJSON}, true, "single-baseof.json",
|
{"JSON with base", TemplateLookupDescriptor{TemplateDir: workingDir, WorkingDir: workingDir, LayoutDir: layoutBase1, RelPath: layoutPathJSON}, true, "single-baseof.json",
|
||||||
|
|
Loading…
Reference in a new issue