diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-17 09:59:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-17 22:13:29 +0200 |
commit | 5d857165fed4649c3aa639a1555a15b8b1c75bab (patch) | |
tree | 9eafd7d8b85ec4c9bc9a16c83172c3a2b1d57e41 /hugolib | |
parent | 0106cf1a6db73f76b7f26744fcee6ce7f41cdf07 (diff) |
Deprecate site.Language.Params and some other fixes
Updates #10947
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/config_test.go | 38 | ||||
-rw-r--r-- | hugolib/hugo_sites_build.go | 6 | ||||
-rw-r--r-- | hugolib/site_new.go | 14 |
3 files changed, 53 insertions, 5 deletions
diff --git a/hugolib/config_test.go b/hugolib/config_test.go index aa7785f92..93060134d 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -742,19 +742,35 @@ themeconfigdirparam: {{ site.Params.themeconfigdirparam }} } -// TODO(beo) find a better place for this. func TestReproCommentsIn10947(t *testing.T) { t.Parallel() files := ` -- hugo.toml -- baseURL = "https://example.com" --- content/mysection/_index.md -- +disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"] +[languages] +[languages.en] +title = "English Title" +[languages.en.params] +myparam = "enParamValue" +[languages.sv] +title = "Svensk Title" +[languages.sv.params] +myparam = "svParamValue" +-- content/mysection/_index.en.md -- +--- +title: "My English Section" --- -title: "My Section" +-- content/mysection/_index.sv.md -- +--- +title: "My Swedish Section" --- -- layouts/index.html -- -Sections: {{ if site.Sections }}true{{ end }}| +{{ range $i, $e := (slice site .Site) }} +{{ $i }}|AllPages: {{ len .AllPages }}|Sections: {{ if .Sections }}true{{ end }}| Author: {{ .Authors }}|BuildDrafts: {{ .BuildDrafts }}|IsMultiLingual: {{ .IsMultiLingual }}|Param: {{ .Language.Params.myparam }}| +{{ end }} + ` @@ -765,6 +781,18 @@ Sections: {{ if site.Sections }}true{{ end }}| }, ).Build() - b.AssertFileContent("public/index.html", "Sections: true|") + b.Assert(b.H.Log.LogCounters().WarnCounter.Count(), qt.Equals, uint64(2)) + b.AssertFileContent("public/index.html", ` +AllPages: 4| +Sections: true| +Param: enParamValue +Param: enParamValue +IsMultiLingual: true +`) + + b.AssertFileContent("public/sv/index.html", ` +Param: svParamValue + +`) } diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 52ed34bf3..f86d425b3 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/publisher" "github.com/gohugoio/hugo/hugofs" @@ -40,6 +41,11 @@ import ( "github.com/gohugoio/hugo/helpers" ) +func init() { + // To avoid circular dependencies, we set this here. + langs.DeprecationFunc = helpers.Deprecated +} + // Build builds all sites. If filesystem events are provided, // this is considered to be a potential partial rebuild. func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error { diff --git a/hugolib/site_new.go b/hugolib/site_new.go index f449b857a..2b959a8da 100644 --- a/hugolib/site_new.go +++ b/hugolib/site_new.go @@ -132,6 +132,8 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) { return nil, err } + langs.SetParams(language, conf.Params) + s := &Site{ conf: conf, language: language, @@ -411,6 +413,10 @@ func (s *Site) Author() map[string]any { return s.conf.Author } +func (s *Site) Authors() page.AuthorList { + return page.AuthorList{} +} + func (s *Site) Social() map[string]string { return s.conf.Social } @@ -434,6 +440,14 @@ func (s *Site) Data() map[string]any { return s.s.h.Data() } +func (s *Site) BuildDrafts() bool { + return s.conf.BuildDrafts +} + +func (s *Site) IsMultiLingual() bool { + return s.h.isMultiLingual() +} + func (s *Site) LanguagePrefix() string { conf := s.s.Conf if !conf.IsMultiLingual() { |