diff options
author | Paul Gottschling <paul.gottschling@gmail.com> | 2022-01-14 16:08:11 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-01-27 11:51:13 +0100 |
commit | 85d31f7bfb7a13c9ab7655829a315a820dc1b403 (patch) | |
tree | 644b2a70f1c30afa20589dd7f28b6a93d32333c6 /hugolib/page_test.go | |
parent | 22055176d23417ac9039f14efdc668ed6cc6a7b9 (diff) |
Fix .RenderString issue in .Translations
Fixes #9383
Diffstat (limited to 'hugolib/page_test.go')
-rw-r--r-- | hugolib/page_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go index fc01bbf25..48a81ee4a 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -768,6 +768,69 @@ Here is the last report for commits in the year 2016. It covers hrev50718-hrev50 `) } +// Issue 9383 +func TestRenderStringForRegularPageTranslations(t *testing.T) { + c := qt.New(t) + b := newTestSitesBuilder(t) + b.WithLogger(loggers.NewBasicLoggerForWriter(jwalterweatherman.LevelDebug, os.Stderr)) + + b.WithConfigFile("toml", + `baseurl = "https://example.org/" +title = "My Site" + +defaultContentLanguage = "ru" +defaultContentLanguageInSubdir = true + +[languages.ru] +contentDir = 'content/ru' +weight = 1 + +[languages.en] +weight = 2 +contentDir = 'content/en' + +[outputs] +home = ["HTML", "JSON"]`) + + b.WithTemplates("index.html", ` +{{- range .Site.Home.Translations -}} + <p>{{- .RenderString "foo" -}}</p> +{{- end -}} +{{- range .Site.Home.AllTranslations -}} + <p>{{- .RenderString "bar" -}}</p> +{{- end -}} +`, "_default/single.html", + `{{ .Content }}`, + "index.json", + `{"Title": "My Site"}`, + ) + + b.WithContent( + "ru/a.md", + "", + "en/a.md", + "", + ) + + err := b.BuildE(BuildCfg{}) + c.Assert(err, qt.Equals, nil) + + b.AssertFileContent("public/ru/index.html", ` +<p>foo</p> +<p>foo</p> +<p>bar</p> +<p>bar</p> +`) + + b.AssertFileContent("public/en/index.html", ` +<p>foo</p> +<p>foo</p> +<p>bar</p> +<p>bar</p> +`) + +} + // Issue 8919 func TestContentProviderWithCustomOutputFormat(t *testing.T) { b := newTestSitesBuilder(t) |