Skip to content

Commit

Permalink
Improve behavior of defaultContentLanguageInSubdir when only the defa…
Browse files Browse the repository at this point in the history
…ult language is enabled

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)

Fixes #11229
  • Loading branch information
bep committed Jul 13, 2023
1 parent 4da672a commit cc44583
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
})

}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cc44583

Please sign in to comment.