output: Fix the shortcodes/partials vs base template detection
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 2 Jul 2018 08:33:55 +0000 (10:33 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 2 Jul 2018 08:34:38 +0000 (10:34 +0200)
Fixes #4897

output/layout_base.go
output/layout_base_test.go

index 31e1194f408c33511adccb36e5c44b7b28b85d07..d3c52347c64429bd60a4724fb7f6f68c156c83a5 100644 (file)
@@ -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
index 719407524d31d845aa8f037fd775ec2cb02eacde..25294c91870d6691bd2d986143978aa0bc2db23d 100644 (file)
@@ -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",