diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-04-19 18:06:40 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-04-21 22:02:56 +0200 |
commit | 4d26ab33dcef704086f43828d1dfb4b8beae2593 (patch) | |
tree | 986c2a878326238ad62dc13c76ed311fef1a855e /hugolib/site_render.go | |
parent | d6a2024e6b675ca30629bbbc7e8a6592defc942c (diff) | |
download | hugo-4d26ab33dcef704086f43828d1dfb4b8beae2593.tar.gz hugo-4d26ab33dcef704086f43828d1dfb4b8beae2593.zip |
Make .Content (almost) always available in shortcodes
This resolves some surprising behaviour when reading other pages' content from shortcodes. Before this commit, that behaviour was undefined. Note that this has never been an issue from regular templates.
It will still not be possible to get **the current shortcode's page's rendered content**. That would have impressed Einstein.
The new and well defined rules are:
* `.Page.Content` from a shortcode will be empty. The related `.Page.Truncated` `.Page.Summary`, `.Page.WordCount`, `.Page.ReadingTime`, `.Page.Plain` and `.Page.PlainWords` will also have empty values.
* For _other pages_ (retrieved via `.Page.Site.GetPage`, `.Site.Pages` etc.) the `.Content` is there to use as you please as long as you don't have infinite content recursion in your shortcode/content setup. See below.
* `.Page.TableOfContents` is good to go (but does not support shortcodes in headlines; this is unchanged)
If you get into a situation of infinite recursion, the `.Content` will be empty. Run `hugo -v` for more information.
Fixes #4632
Fixes #4653
Fixes #4655
Diffstat (limited to 'hugolib/site_render.go')
-rw-r--r-- | hugolib/site_render.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/hugolib/site_render.go b/hugolib/site_render.go index a2031e0c0..e9d2f0183 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -44,7 +44,6 @@ func (s *Site) renderPages(cfg *BuildCfg) error { if len(s.headlessPages) > 0 { wg.Add(1) go headlessPagesPublisher(s, wg) - } for _, page := range s.Pages { @@ -70,6 +69,10 @@ func headlessPagesPublisher(s *Site, wg *sync.WaitGroup) { defer wg.Done() for _, page := range s.headlessPages { outFormat := page.outputFormats[0] // There is only one + if outFormat != s.rc.Format { + // Avoid double work. + continue + } pageOutput, err := newPageOutput(page, false, outFormat) if err == nil { page.mainPageOutput = pageOutput |