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.
This commit is contained in:
Bjørn Erik Pedersen
2017-03-26 19:34:30 +02:00
parent e49a2b83ad
commit 930a3df1b7
6 changed files with 50 additions and 16 deletions

View File

@@ -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,