mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-02 20:59:04 +00:00
Get rid of the rawContentCopy field of the Page struct
It is not needed, because it is only used to store temporary data during `preparePagesForRender`.
This commit is contained in:
parent
c936b6c89a
commit
89e3125664
2 changed files with 19 additions and 22 deletions
|
@ -458,47 +458,49 @@ func (s *Site) preparePagesForRender(cfg BuildCfg, changed whatChanged) {
|
||||||
|
|
||||||
// If in watch mode, we need to keep the original so we can
|
// If in watch mode, we need to keep the original so we can
|
||||||
// repeat this process on rebuild.
|
// repeat this process on rebuild.
|
||||||
|
var rawContentCopy []byte
|
||||||
if cfg.Watching {
|
if cfg.Watching {
|
||||||
p.rawContentCopy = make([]byte, len(p.rawContent))
|
rawContentCopy = make([]byte, len(p.rawContent))
|
||||||
copy(p.rawContentCopy, p.rawContent)
|
copy(rawContentCopy, p.rawContent)
|
||||||
} else {
|
} else {
|
||||||
// Just reuse the same slice.
|
// Just reuse the same slice.
|
||||||
p.rawContentCopy = p.rawContent
|
rawContentCopy = p.rawContent
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Markup == "markdown" {
|
if p.Markup == "markdown" {
|
||||||
tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.rawContentCopy)
|
tmpContent, tmpTableOfContents := helpers.ExtractTOC(rawContentCopy)
|
||||||
p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
|
p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
|
||||||
p.rawContentCopy = tmpContent
|
rawContentCopy = tmpContent
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := handleShortcodes(p, s.owner.tmpl); err != nil {
|
var err error
|
||||||
|
if rawContentCopy, err = handleShortcodes(p, s.owner.tmpl, rawContentCopy); err != nil {
|
||||||
jww.ERROR.Printf("Failed to handle shortcodes for page %s: %s", p.BaseFileName(), err)
|
jww.ERROR.Printf("Failed to handle shortcodes for page %s: %s", p.BaseFileName(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Markup != "html" {
|
if p.Markup != "html" {
|
||||||
|
|
||||||
// Now we know enough to create a summary of the page and count some words
|
// Now we know enough to create a summary of the page and count some words
|
||||||
summaryContent, err := p.setUserDefinedSummaryIfProvided()
|
summaryContent, err := p.setUserDefinedSummaryIfProvided(rawContentCopy)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jww.ERROR.Printf("Failed to set user defined summary for page %q: %s", p.Path(), err)
|
jww.ERROR.Printf("Failed to set user defined summary for page %q: %s", p.Path(), err)
|
||||||
} else if summaryContent != nil {
|
} else if summaryContent != nil {
|
||||||
p.rawContentCopy = summaryContent.content
|
rawContentCopy = summaryContent.content
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Content = helpers.BytesToHTML(p.rawContentCopy)
|
p.Content = helpers.BytesToHTML(rawContentCopy)
|
||||||
|
|
||||||
if summaryContent == nil {
|
if summaryContent == nil {
|
||||||
p.setAutoSummary()
|
p.setAutoSummary()
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
p.Content = helpers.BytesToHTML(p.rawContentCopy)
|
p.Content = helpers.BytesToHTML(rawContentCopy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need for this anymore
|
// no need for this anymore
|
||||||
p.rawContentCopy = nil
|
rawContentCopy = nil
|
||||||
|
|
||||||
//analyze for raw stats
|
//analyze for raw stats
|
||||||
p.analyzePage()
|
p.analyzePage()
|
||||||
|
@ -522,23 +524,23 @@ func (h *HugoSites) Pages() Pages {
|
||||||
return h.Sites[0].AllPages
|
return h.Sites[0].AllPages
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleShortcodes(p *Page, t tpl.Template) error {
|
func handleShortcodes(p *Page, t tpl.Template, rawContentCopy []byte) ([]byte, error) {
|
||||||
if len(p.contentShortCodes) > 0 {
|
if len(p.contentShortCodes) > 0 {
|
||||||
jww.DEBUG.Printf("Replace %d shortcodes in %q", len(p.contentShortCodes), p.BaseFileName())
|
jww.DEBUG.Printf("Replace %d shortcodes in %q", len(p.contentShortCodes), p.BaseFileName())
|
||||||
shortcodes, err := executeShortcodeFuncMap(p.contentShortCodes)
|
shortcodes, err := executeShortcodeFuncMap(p.contentShortCodes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return rawContentCopy, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.rawContentCopy, err = replaceShortcodeTokens(p.rawContentCopy, shortcodePlaceholderPrefix, shortcodes)
|
rawContentCopy, err = replaceShortcodeTokens(rawContentCopy, shortcodePlaceholderPrefix, shortcodes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jww.FATAL.Printf("Failed to replace short code tokens in %s:\n%s", p.BaseFileName(), err.Error())
|
jww.FATAL.Printf("Failed to replace short code tokens in %s:\n%s", p.BaseFileName(), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return rawContentCopy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) updateBuildStats(page *Page) {
|
func (s *Site) updateBuildStats(page *Page) {
|
||||||
|
|
|
@ -76,11 +76,6 @@ type Page struct {
|
||||||
// when shortcode changes etc.
|
// when shortcode changes etc.
|
||||||
rawContent []byte
|
rawContent []byte
|
||||||
|
|
||||||
// When running Hugo in watch mode, we do partial rebuilds and have to make
|
|
||||||
// a copy of the rawContent to be prepared for rebuilds when shortcodes etc.
|
|
||||||
// have changed.
|
|
||||||
rawContentCopy []byte
|
|
||||||
|
|
||||||
// state telling if this is a "new page" or if we have rendered it previously.
|
// state telling if this is a "new page" or if we have rendered it previously.
|
||||||
rendered bool
|
rendered bool
|
||||||
|
|
||||||
|
@ -258,9 +253,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns the page as summary and main if a user defined split is provided.
|
// Returns the page as summary and main if a user defined split is provided.
|
||||||
func (p *Page) setUserDefinedSummaryIfProvided() (*summaryContent, error) {
|
func (p *Page) setUserDefinedSummaryIfProvided(rawContentCopy []byte) (*summaryContent, error) {
|
||||||
|
|
||||||
sc, err := splitUserDefinedSummaryAndContent(p.Markup, p.rawContentCopy)
|
sc, err := splitUserDefinedSummaryAndContent(p.Markup, rawContentCopy)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue