Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-05-08 11:10:13 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-05-08 17:52:51 +0300
commit086ae81a98149de6b220cc7e2f155d15f0bc17e3 (patch)
tree3784e998e8fa52bae70e3c5737e3acaf6b865897 /hugolib/page_output.go
parentc2bb62d63eb17e00b692b56f0ef2abf7db6009cf (diff)
hugolib: Fix possible .Content cut
There have been one report of a site with truncated `.Content` after the Hugo `0.40.1` release. This commit fixes this so that race should not be possible anymore. It also adds a stress test with focus on content rendering and multiple output formats. Fixes #4706
Diffstat (limited to 'hugolib/page_output.go')
-rw-r--r--hugolib/page_output.go28
1 files changed, 5 insertions, 23 deletions
diff --git a/hugolib/page_output.go b/hugolib/page_output.go
index 0a51e72f7..5893bc172 100644
--- a/hugolib/page_output.go
+++ b/hugolib/page_output.go
@@ -55,7 +55,7 @@ func (p *PageOutput) targetPath(addends ...string) (string, error) {
return tp, nil
}
-func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, error) {
+func newPageOutput(p *Page, createCopy, initContent bool, f output.Format) (*PageOutput, error) {
// TODO(bep) This is only needed for tests and we should get rid of it.
if p.targetPathDescriptorPrototype == nil {
if err := p.initPaths(); err != nil {
@@ -64,7 +64,7 @@ func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, erro
}
if createCopy {
- p = p.copy()
+ p = p.copy(initContent)
}
td, err := p.createTargetPathDescriptor(f)
@@ -82,8 +82,8 @@ func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, erro
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
// so they will be evaluated again, for word count calculations etc.
-func (p *PageOutput) copyWithFormat(f output.Format) (*PageOutput, error) {
- c, err := newPageOutput(p.Page, true, f)
+func (p *PageOutput) copyWithFormat(f output.Format, initContent bool) (*PageOutput, error) {
+ c, err := newPageOutput(p.Page, true, initContent, f)
if err != nil {
return nil, err
}
@@ -92,7 +92,7 @@ func (p *PageOutput) copyWithFormat(f output.Format) (*PageOutput, error) {
}
func (p *PageOutput) copy() (*PageOutput, error) {
- return p.copyWithFormat(p.outputFormat)
+ return p.copyWithFormat(p.outputFormat, false)
}
func (p *PageOutput) layouts(layouts ...string) ([]string, error) {
@@ -142,24 +142,6 @@ func (p *PageOutput) Render(layout ...string) template.HTML {
}
func (p *Page) Render(layout ...string) template.HTML {
- p.pageOutputInit.Do(func() {
- if p.mainPageOutput != nil {
- return
- }
- // If Render is called in a range loop, the page output isn't available.
- // So, create one.
- outFormat := p.outputFormats[0]
- pageOutput, err := newPageOutput(p, true, outFormat)
-
- if err != nil {
- p.s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outFormat.Name, p.pathOrTitle(), err)
- return
- }
-
- p.mainPageOutput = pageOutput
-
- })
-
return p.mainPageOutput.Render(layout...)
}