Repository: gohugoio/hugo (language: go)

Issue:
Improve behavior of defaultContentLanguageInSubdir when only the default language is enabled
Follow-on to #10064.

1. Create sitemapindex in root of publishDir (will contain link to sitemap.xml in defaultContentLanguage site)
2. Create index.html in root of publishDir (will redirect to defaultContentLanguage site)


Discussion / hints:

Fix patch:
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 9c121f7ac11..de19a3669b1 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -437,7 +437,7 @@ func (cfg *BuildCfg) shouldRender(p *pageState) bool {
 }
 
 func (h *HugoSites) renderCrossSitesSitemap() error {
-	if !h.isMultiLingual() || h.Conf.IsMultihost() {
+	if h.Conf.IsMultihost() || !(h.Conf.DefaultContentLanguageInSubdir() || h.Conf.IsMultiLingual()) {
 		return nil
 	}
 
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 65809a37786..89dc5ac77a6 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -557,6 +557,9 @@ func (p *pageContentOutput) RenderWithTemplateInfo(ctx context.Context, info tpl
 }
 
 func (p *pageContentOutput) Render(ctx context.Context, layout ...string) (template.HTML, error) {
+	if len(layout) == 0 {
+		return "", errors.New("no layout given")
+	}
 	templ, found, err := p.p.resolveTemplate(layout...)
 	if err != nil {
 		return "", p.p.wrapError(err)
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index c4c3f389ba8..f9c1dd498c4 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -384,7 +384,7 @@ func (s *Site) renderAliases() error {
 // renderMainLanguageRedirect creates a redirect to the main language home,
 // depending on if it lives in sub folder (e.g. /en) or not.
 func (s *Site) renderMainLanguageRedirect() error {
-	if !s.h.isMultiLingual() || s.h.Conf.IsMultihost() {
+	if s.h.Conf.IsMultihost() || !(s.h.Conf.DefaultContentLanguageInSubdir() || s.h.Conf.IsMultiLingual()) {
 		// No need for a redirect
 		return nil
 	}


Test patch:
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index cdac0fbab93..100144ca146 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -1321,6 +1321,9 @@ Home.
 
 		b.AssertFileContent("public/en/index.html", "Home.")
 		b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
+		b.AssertFileContent("public/index.html", "refresh")
+		b.AssertFileContent("public/sitemap.xml", "sitemapindex")
+		b.AssertFileContent("public/en/sitemap.xml", "urlset")
 	})
 
 	t.Run("Two languages, default in sub dir", func(t *testing.T) {
@@ -1351,6 +1354,9 @@ Home.
 
 		b.AssertFileContent("public/en/index.html", "Home.")
 		b.AssertFileContent("public/en/foo/bar.txt", "Foo.")
+		b.AssertFileContent("public/index.html", "refresh")
+		b.AssertFileContent("public/sitemap.xml", "sitemapindex")
+		b.AssertFileContent("public/en/sitemap.xml", "urlset")
 	})
 
 	t.Run("Two languages, default in root", func(t *testing.T) {
@@ -1381,6 +1387,8 @@ Home.
 
 		b.AssertFileContent("public/index.html", "Home.")
 		b.AssertFileContent("public/foo/bar.txt", "Foo.")
+		b.AssertFileContent("public/sitemap.xml", "sitemapindex")
+		b.AssertFileContent("public/en/sitemap.xml", "urlset")
 	})
 
 }
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 162f260527c..5237b634096 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1983,3 +1983,25 @@ title: "p2"
 	b.Assert(identity.HashString(p1), qt.Not(qt.Equals), identity.HashString(p2))
 	b.Assert(identity.HashString(sites[0]), qt.Not(qt.Equals), identity.HashString(sites[1]))
 }
+
+// Issue #11243
+func TestRenderWithoutArgument(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+-- layouts/index.html --
+{{ .Render }}
+`
+
+	b, err := NewIntegrationTestBuilder(
+		IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+			Running:     true,
+		},
+	).BuildE()
+
+	b.Assert(err, qt.IsNotNil)
+
+}