summaryrefslogtreecommitdiffstats
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-02 10:33:55 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-02 10:34:38 +0200
commita5d0a57e6bdab583134a68c035aac9b3007f006a (patch)
treefc9f17a67d8f0a49d1cfcf8576d608acc722d790 /output
parentf465571b33c8736a95534dd43f07527869d1eec3 (diff)
output: Fix the shortcodes/partials vs base template detection
Fixes #4897
Diffstat (limited to 'output')
-rw-r--r--output/layout_base.go10
-rw-r--r--output/layout_base_test.go12
2 files changed, 19 insertions, 3 deletions
diff --git a/output/layout_base.go b/output/layout_base.go
index 31e1194f4..d3c52347c 100644
--- a/output/layout_base.go
+++ b/output/layout_base.go
@@ -58,6 +58,10 @@ type TemplateLookupDescriptor struct {
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) {
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.
- pathDir := filepath.Dir(d.RelPath)
-
- if ext == "amber" || strings.HasSuffix(pathDir, "partials") || strings.HasSuffix(pathDir, "shortcodes") {
+ if ext == "amber" || isShorthCodeOrPartial(name) {
// No base template support
return id, nil
}
+ pathDir := filepath.Dir(d.RelPath)
+
innerMarkers := goTemplateInnerMarkers
var baseFilename string
diff --git a/output/layout_base_test.go b/output/layout_base_test.go
index 719407524..25294c918 100644
--- a/output/layout_base_test.go
+++ b/output/layout_base_test.go
@@ -75,6 +75,18 @@ func TestLayoutBase(t *testing.T) {
Name: "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, "",
TemplateNames{
Name: "_default/single.amp.html",