mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
0c01fef321
commit
8cea428802
3 changed files with 28 additions and 18 deletions
|
@ -66,6 +66,7 @@ type Page struct {
|
|||
contentType string
|
||||
renderable bool
|
||||
Layout string
|
||||
layoutsCalculated []string
|
||||
linkTitle string
|
||||
frontmatter []byte
|
||||
rawContent []byte
|
||||
|
@ -288,6 +289,10 @@ func (p *Page) Section() string {
|
|||
}
|
||||
|
||||
func (p *Page) layouts(l ...string) []string {
|
||||
if len(p.layoutsCalculated) > 0 {
|
||||
return p.layoutsCalculated
|
||||
}
|
||||
|
||||
if p.Layout != "" {
|
||||
return layouts(p.Type(), p.Layout)
|
||||
}
|
||||
|
|
|
@ -920,6 +920,26 @@ func (s *Site) RenderPages() error {
|
|||
|
||||
procs := getGoMaxProcs()
|
||||
|
||||
// this cannot be fanned out to multiple Go routines
|
||||
// See issue #1601
|
||||
// TODO(bep): Check the IsRenderable logic.
|
||||
for _, p := range s.Pages {
|
||||
var layouts []string
|
||||
if !p.IsRenderable() {
|
||||
self := "__" + p.TargetPath()
|
||||
_, err := s.Tmpl.New(self).Parse(string(p.Content))
|
||||
if err != nil {
|
||||
results <- err
|
||||
continue
|
||||
}
|
||||
layouts = append(layouts, self)
|
||||
} else {
|
||||
layouts = append(layouts, p.layouts()...)
|
||||
layouts = append(layouts, "_default/single.html")
|
||||
}
|
||||
p.layoutsCalculated = layouts
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
for i := 0; i < procs*4; i++ {
|
||||
|
@ -951,22 +971,7 @@ func (s *Site) RenderPages() error {
|
|||
func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
for p := range pages {
|
||||
var layouts []string
|
||||
|
||||
if !p.IsRenderable() {
|
||||
self := "__" + p.TargetPath()
|
||||
_, err := s.Tmpl.New(self).Parse(string(p.Content))
|
||||
if err != nil {
|
||||
results <- err
|
||||
continue
|
||||
}
|
||||
layouts = append(layouts, self)
|
||||
} else {
|
||||
layouts = append(layouts, p.layouts()...)
|
||||
layouts = append(layouts, "_default/single.html")
|
||||
}
|
||||
|
||||
err := s.renderAndWritePage("page "+p.FullFilePath(), p.TargetPath(), p, s.appendThemeTemplates(layouts)...)
|
||||
err := s.renderAndWritePage("page "+p.FullFilePath(), p.TargetPath(), p, s.appendThemeTemplates(p.layouts())...)
|
||||
if err != nil {
|
||||
results <- err
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ func TestRenderThing(t *testing.T) {
|
|||
templateName := fmt.Sprintf("foobar%d", i)
|
||||
err = s.addTemplate(templateName, test.template)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to add template")
|
||||
t.Fatalf("Unable to add template: %s", err)
|
||||
}
|
||||
|
||||
p.Content = template.HTML(p.Content)
|
||||
|
@ -203,7 +203,7 @@ func TestRenderThingOrDefault(t *testing.T) {
|
|||
templateName := fmt.Sprintf("default%d", i)
|
||||
err = s.addTemplate(templateName, test.template)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to add template")
|
||||
t.Fatalf("Unable to add template: %s", err)
|
||||
}
|
||||
|
||||
var err2 error
|
||||
|
|
Loading…
Reference in a new issue