From 2f026ab3f3866852794c4c9ceec834b54b0e0921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 1 Dec 2016 10:21:49 +0100 Subject: [PATCH] hugolib: Make RawContent raw again This was a regression introduced in Hugo 0.17. Fixes #2601 --- hugolib/handler_page.go | 12 +++++++++--- hugolib/hugo_sites.go | 24 ++++++++++++------------ hugolib/hugo_sites_build_test.go | 2 +- hugolib/page.go | 17 +++++++++++------ hugolib/page_test.go | 20 ++++++++++++++++++++ 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/hugolib/handler_page.go b/hugolib/handler_page.go index 45e34973d..404526acc 100644 --- a/hugolib/handler_page.go +++ b/hugolib/handler_page.go @@ -72,6 +72,9 @@ func (h htmlHandler) PageConvert(p *Page, t tpl.Template) HandledResult { panic(fmt.Sprintf("Page %q already rendered, does not need conversion", p.BaseFileName())) } + // Work on a copy of the raw content from now on. + p.createWorkContentCopy() + p.ProcessShortcodes(t) return HandledResult{err: nil} @@ -109,19 +112,22 @@ func commonConvert(p *Page, t tpl.Template) HandledResult { panic(fmt.Sprintf("Page %q already rendered, does not need conversion", p.BaseFileName())) } + // Work on a copy of the raw content from now on. + p.createWorkContentCopy() + p.ProcessShortcodes(t) // TODO(bep) these page handlers need to be re-evaluated, as it is hard to // process a page in isolation. See the new preRender func. if viper.GetBool("enableEmoji") { - p.rawContent = helpers.Emojify(p.rawContent) + p.workContent = helpers.Emojify(p.workContent) } // We have to replace the with something that survives all the // rendering engines. // TODO(bep) inline replace - p.rawContent = bytes.Replace(p.rawContent, []byte(helpers.SummaryDivider), internalSummaryDivider, 1) - p.rawContent = p.renderContent(p.rawContent) + p.workContent = bytes.Replace(p.workContent, []byte(helpers.SummaryDivider), internalSummaryDivider, 1) + p.workContent = p.renderContent(p.workContent) return HandledResult{err: nil} } diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 2794ad37d..7ebcfe0c6 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -368,49 +368,49 @@ func (s *Site) preparePagesForRender(cfg *BuildCfg) { // If in watch mode, we need to keep the original so we can // repeat this process on rebuild. - var rawContentCopy []byte + var workContentCopy []byte if cfg.Watching { - rawContentCopy = make([]byte, len(p.rawContent)) - copy(rawContentCopy, p.rawContent) + workContentCopy = make([]byte, len(p.workContent)) + copy(workContentCopy, p.workContent) } else { // Just reuse the same slice. - rawContentCopy = p.rawContent + workContentCopy = p.workContent } if p.Markup == "markdown" { - tmpContent, tmpTableOfContents := helpers.ExtractTOC(rawContentCopy) + tmpContent, tmpTableOfContents := helpers.ExtractTOC(workContentCopy) p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents) - rawContentCopy = tmpContent + workContentCopy = tmpContent } var err error - if rawContentCopy, err = handleShortcodes(p, s.owner.tmpl, rawContentCopy); err != nil { + if workContentCopy, err = handleShortcodes(p, s.owner.tmpl, workContentCopy); err != nil { jww.ERROR.Printf("Failed to handle shortcodes for page %s: %s", p.BaseFileName(), err) } if p.Markup != "html" { // Now we know enough to create a summary of the page and count some words - summaryContent, err := p.setUserDefinedSummaryIfProvided(rawContentCopy) + summaryContent, err := p.setUserDefinedSummaryIfProvided(workContentCopy) if err != nil { jww.ERROR.Printf("Failed to set user defined summary for page %q: %s", p.Path(), err) } else if summaryContent != nil { - rawContentCopy = summaryContent.content + workContentCopy = summaryContent.content } - p.Content = helpers.BytesToHTML(rawContentCopy) + p.Content = helpers.BytesToHTML(workContentCopy) if summaryContent == nil { p.setAutoSummary() } } else { - p.Content = helpers.BytesToHTML(rawContentCopy) + p.Content = helpers.BytesToHTML(workContentCopy) } // no need for this anymore - rawContentCopy = nil + workContentCopy = nil //analyze for raw stats p.analyzePage() diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 10b5baad3..59670dd31 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -560,7 +560,7 @@ func assertShouldNotBuild(t *testing.T, sites *HugoSites) { for _, p := range s.rawAllPages { // No HTML when not processed - require.Equal(t, p.shouldBuild(), bytes.Contains(p.rawContent, []byte("