mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
output: Fix the shortcodes/partials vs base template detection
Fixes #4897
This commit is contained in:
parent
f465571b33
commit
a5d0a57e6b
2 changed files with 19 additions and 3 deletions
|
@ -58,6 +58,10 @@ type TemplateLookupDescriptor struct {
|
||||||
ContainsAny func(filename string, subslices [][]byte) (bool, error)
|
ContainsAny func(filename string, subslices [][]byte) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isShorthCodeOrPartial(name string) bool {
|
||||||
|
return strings.HasPrefix(name, "shortcodes/") || strings.HasPrefix(name, "partials/")
|
||||||
|
}
|
||||||
|
|
||||||
func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
|
func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
|
||||||
|
|
||||||
name := filepath.ToSlash(d.RelPath)
|
name := filepath.ToSlash(d.RelPath)
|
||||||
|
@ -104,13 +108,13 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ace and Go templates may have both a base and inner template.
|
// Ace and Go templates may have both a base and inner template.
|
||||||
pathDir := filepath.Dir(d.RelPath)
|
if ext == "amber" || isShorthCodeOrPartial(name) {
|
||||||
|
|
||||||
if ext == "amber" || strings.HasSuffix(pathDir, "partials") || strings.HasSuffix(pathDir, "shortcodes") {
|
|
||||||
// No base template support
|
// No base template support
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pathDir := filepath.Dir(d.RelPath)
|
||||||
|
|
||||||
innerMarkers := goTemplateInnerMarkers
|
innerMarkers := goTemplateInnerMarkers
|
||||||
|
|
||||||
var baseFilename string
|
var baseFilename string
|
||||||
|
|
|
@ -75,6 +75,18 @@ func TestLayoutBase(t *testing.T) {
|
||||||
Name: "partials/menu.html",
|
Name: "partials/menu.html",
|
||||||
OverlayFilename: "partials/menu.html",
|
OverlayFilename: "partials/menu.html",
|
||||||
}},
|
}},
|
||||||
|
{"Partial in subfolder", TemplateLookupDescriptor{WorkingDir: workingDir, RelPath: "/partials/sub/menu.html"}, true,
|
||||||
|
"_default/baseof.html",
|
||||||
|
TemplateNames{
|
||||||
|
Name: "partials/sub/menu.html",
|
||||||
|
OverlayFilename: "/partials/sub/menu.html",
|
||||||
|
}},
|
||||||
|
{"Shortcode in subfolder", TemplateLookupDescriptor{WorkingDir: workingDir, RelPath: "shortcodes/sub/menu.html"}, true,
|
||||||
|
"_default/baseof.html",
|
||||||
|
TemplateNames{
|
||||||
|
Name: "shortcodes/sub/menu.html",
|
||||||
|
OverlayFilename: "shortcodes/sub/menu.html",
|
||||||
|
}},
|
||||||
{"AMP, no base", TemplateLookupDescriptor{WorkingDir: workingDir, RelPath: layoutPathAmp}, false, "",
|
{"AMP, no base", TemplateLookupDescriptor{WorkingDir: workingDir, RelPath: layoutPathAmp}, false, "",
|
||||||
TemplateNames{
|
TemplateNames{
|
||||||
Name: "_default/single.amp.html",
|
Name: "_default/single.amp.html",
|
||||||
|
|
Loading…
Reference in a new issue