}
-// 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 }}
+
`
},
).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
+
+`)
}
"strings"
"time"
+ "github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/publisher"
"github.com/gohugoio/hugo/hugofs"
"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 {
return nil, err
}
+ langs.SetParams(language, conf.Params)
+
s := &Site{
conf: conf,
language: language,
return s.conf.Author
}
+func (s *Site) Authors() page.AuthorList {
+ return page.AuthorList{}
+}
+
func (s *Site) Social() map[string]string {
return s.conf.Social
}
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() {
"golang.org/x/text/language"
"github.com/gohugoio/hugo/common/htime"
+ "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/locales"
translators "github.com/gohugoio/localescompressed"
)
tag language.Tag
collator *Collator
location *time.Location
+
+ // This is just an alias of Site.Params.
+ params maps.Params
}
// NewLanguage creates a new language.
}
return l, l.loadLocation(timeZone)
+}
+
+// This is injected from hugolib to avoid cirular dependencies.
+var DeprecationFunc = func(item, alternative string, err bool) {}
+
+const paramsDeprecationWarning = `.Language.Params is deprecated and will be removed in a future release. Use site.Params instead.
+
+Also, for all but custom parameters, you need to use the built in Hugo variables, e.g. site.Title, site.LanguageCode; site.Language.Params.Title will not work.
+See https://gohugo.io/content-management/multilingual/#changes-in-hugo-01120
+
+`
+
+// Params returns the language params.
+// Note that this is the same as the Site.Params, but we keep it here for legacy reasons.
+// Deprecated: Use the site.Params instead.
+func (l *Language) Params() maps.Params {
+ DeprecationFunc(".Language.Params", paramsDeprecationWarning, false)
+ return l.params
}
func (l *Language) loadLocation(tzStr string) error {
// Internal access to unexported Language fields.
// This construct is to prevent them from leaking to the templates.
+func SetParams(l *Language, params maps.Params) {
+ l.params = params
+}
+
func GetTimeFormatter(l *Language) htime.TimeFormatter {
return l.timeFormatter
}
GetPage(ref ...string) (Page, error)
+ // AllPages returns all pages for all languages.
+ AllPages() Pages
+
// Returns all the regular Pages in this Site.
RegularPages() Pages
// Author is deprecated and will be removed in a future release.
Author() map[string]interface{}
+ // Authors is deprecated and will be removed in a future release.
+ Authors() AuthorList
+
// Returns the social links for this site.
Social() map[string]string
// For internal use only.
GetPageWithTemplateInfo(info tpl.Info, ref ...string) (Page, error)
+
+ // BuildDraft is deprecated and will be removed in a future release.
+ BuildDrafts() bool
+
+ // IsMultilingual reports whether this site is configured with more than one language.
+ IsMultiLingual() bool
}
// Sites represents an ordered list of sites (languages).
func (s *siteWrapper) Author() map[string]interface{} {
return s.s.Author()
}
+func (s *siteWrapper) Authors() AuthorList {
+ return AuthorList{}
+}
func (s *siteWrapper) GoogleAnalytics() string {
return s.s.GoogleAnalytics()
return s.s.Language()
}
+func (s *siteWrapper) AllPages() Pages {
+ return s.s.AllPages()
+}
+
func (s *siteWrapper) RegularPages() Pages {
return s.s.RegularPages()
}
return s.s.GetPageWithTemplateInfo(info, ref...)
}
+func (s *siteWrapper) BuildDrafts() bool {
+ return s.s.BuildDrafts()
+}
+
+func (s *siteWrapper) IsMultiLingual() bool {
+ return s.s.IsMultiLingual()
+}
+
func (s *siteWrapper) DisqusShortname() string {
return s.s.DisqusShortname()
}
func (s testSite) Author() map[string]interface{} {
return nil
}
+func (s testSite) Authors() AuthorList {
+ return AuthorList{}
+}
func (s testSite) Social() map[string]string {
return make(map[string]string)
return nil
}
+func (t testSite) AllPages() Pages {
+ return nil
+}
+
func (t testSite) RegularPages() Pages {
return nil
}
return ""
}
+func (s testSite) BuildDrafts() bool {
+ return false
+}
+
+func (s testSite) IsMultiLingual() bool {
+ return false
+}
+
// NewDummyHugoSite creates a new minimal test site.
func NewDummyHugoSite(cfg config.Provider) Site {
return testSite{