Skip to content

Commit

Permalink
output: Fix the shortcodes/partials vs base template detection
Browse files Browse the repository at this point in the history
Fixes #4897
  • Loading branch information
bep committed Jul 2, 2018
1 parent f465571 commit a5d0a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions output/layout_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions output/layout_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a5d0a57

Please sign in to comment.