From 4d26ab33dcef704086f43828d1dfb4b8beae2593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 19 Apr 2018 18:06:40 +0200 Subject: 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 --- deps/deps.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'deps') diff --git a/deps/deps.go b/deps/deps.go index fd9635444..475d678a9 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "os" + "time" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/helpers" @@ -54,6 +55,9 @@ type Deps struct { translationProvider ResourceProvider Metrics metrics.Provider + + // Timeout is configurable in site config. + Timeout time.Duration } // ResourceProvider is used to create and refresh, and clone resources needed. @@ -128,6 +132,11 @@ func New(cfg DepsCfg) (*Deps, error) { sp := source.NewSourceSpec(ps, fs.Source) + timeoutms := cfg.Language.GetInt("timeout") + if timeoutms <= 0 { + timeoutms = 3000 + } + d := &Deps{ Fs: fs, Log: logger, @@ -139,6 +148,7 @@ func New(cfg DepsCfg) (*Deps, error) { SourceSpec: sp, Cfg: cfg.Language, Language: cfg.Language, + Timeout: time.Duration(timeoutms) * time.Millisecond, } if cfg.Cfg.GetBool("templateMetrics") { -- cgit v1.2.3