aboutsummaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-03-26 19:34:30 +0200
committerBjørn Erik Pedersen <[email protected]>2017-03-27 15:43:56 +0200
commit930a3df1b79d21f005a63918b89cc01ae5a4cd9e (patch)
tree07955b204d91ee67857beb1af2a6d49da4386086 /output
parente49a2b83ad9825a978ecbf0ff5fd9b7331690c17 (diff)
downloadhugo-930a3df1b79d21f005a63918b89cc01ae5a4cd9e.tar.gz
hugo-930a3df1b79d21f005a63918b89cc01ae5a4cd9e.zip
hugolib, output: Restrict Render to regular Pages
Using it for list pages doesn't work and has potential weird side-effects. The user probably meant to range over .Site.ReqularPages, and that is now marked clearly in the log.
Diffstat (limited to 'output')
-rw-r--r--output/layout.go14
-rw-r--r--output/layout_test.go10
2 files changed, 17 insertions, 7 deletions
diff --git a/output/layout.go b/output/layout.go
index cda6eb8a0..a2bfd7717 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -83,19 +83,23 @@ indexes/indexes.NAME.SUFFIX indexes/indexes.SUFFIX
`
)
-func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format) []string {
+func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format) ([]string, error) {
// We will get lots of requests for the same layouts, so avoid recalculations.
key := layoutCacheKey{d, layoutOverride, f}
l.mu.RLock()
if cacheVal, found := l.cache[key]; found {
l.mu.RUnlock()
- return cacheVal
+ return cacheVal, nil
}
l.mu.RUnlock()
var layouts []string
+ if layoutOverride != "" && d.Kind != "page" {
+ return layouts, fmt.Errorf("Custom layout (%q) only supported for regular pages, not kind %q", layoutOverride, d.Kind)
+ }
+
layout := d.Layout
if layoutOverride != "" {
@@ -106,7 +110,7 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format)
if d.Kind == "page" {
if isRSS {
- return []string{}
+ return []string{}, nil
}
layouts = regularPageLayouts(d.Type, layout, f)
} else {
@@ -148,14 +152,14 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format)
}
}
- return layoutsWithThemeLayouts
+ return layoutsWithThemeLayouts, nil
}
l.mu.Lock()
l.cache[key] = layouts
l.mu.Unlock()
- return layouts
+ return layouts, nil
}
func resolveListTemplate(d LayoutDescriptor, f Format,
diff --git a/output/layout_test.go b/output/layout_test.go
index b38bd9c13..e59a16fcb 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -68,8 +68,9 @@ func TestLayout(t *testing.T) {
t.Run(this.name, func(t *testing.T) {
l := NewLayoutHandler(this.hasTheme)
- layouts := l.For(this.d, this.layoutOverride, this.tp)
+ layouts, err := l.For(this.d, this.layoutOverride, this.tp)
+ require.NoError(t, err)
require.NotNil(t, layouts)
require.True(t, len(layouts) >= len(this.expect))
// Not checking the complete list for now ...
@@ -83,6 +84,10 @@ func TestLayout(t *testing.T) {
})
}
+ l := NewLayoutHandler(false)
+ _, err := l.For(LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, "override", RSSFormat)
+ require.Error(t, err)
+
}
func BenchmarkLayout(b *testing.B) {
@@ -90,7 +95,8 @@ func BenchmarkLayout(b *testing.B) {
l := NewLayoutHandler(false)
for i := 0; i < b.N; i++ {
- layouts := l.For(descriptor, "", HTMLFormat)
+ layouts, err := l.For(descriptor, "", HTMLFormat)
+ require.NoError(b, err)
require.NotEmpty(b, layouts)
}
}