diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-06 19:54:46 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-27 15:43:56 +0200 |
commit | 50c64415aa6593ba93bff086602a121aa9760d40 (patch) | |
tree | 56f55d399a09db8d5d83271080a238b834e7afb9 /output/layout.go | |
parent | 348834d0176611fc0a08121b86c40e37644a89e3 (diff) |
hugolib, output: Add theme logic to LayoutHandler
Diffstat (limited to 'output/layout.go')
-rw-r--r-- | output/layout.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/output/layout.go b/output/layout.go index ba246237a..0e0f33dad 100644 --- a/output/layout.go +++ b/output/layout.go @@ -30,6 +30,11 @@ type LayoutIdentifier interface { // Layout calculates the layout template to use to render a given output type. // TODO(bep) output improve names type LayoutHandler struct { + hasTheme bool +} + +func NewLayoutHandler(hasTheme bool) *LayoutHandler { + return &LayoutHandler{hasTheme: hasTheme} } // TODO(bep) output theme layouts @@ -63,8 +68,30 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type) layouts = regularPageLayouts(id.PageType(), layout) } - for _, l := range layouts { - layouts = append(layouts, "theme/"+l) + if l.hasTheme { + layoutsWithThemeLayouts := []string{} + // First place all non internal templates + for _, t := range layouts { + if !strings.HasPrefix(t, "_internal/") { + layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, t) + } + } + + // Then place theme templates with the same names + for _, t := range layouts { + if !strings.HasPrefix(t, "_internal/") { + layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, "theme/"+t) + } + } + + // Lastly place internal templates + for _, t := range layouts { + if strings.HasPrefix(t, "_internal/") { + layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, t) + } + } + + return layoutsWithThemeLayouts } return layouts |