mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 06:30:33 +03:00
parent
e293e7ca6d
commit
75ad9cdaab
3 changed files with 29 additions and 0 deletions
|
@ -505,6 +505,9 @@ type RootConfig struct {
|
||||||
// Set this to true to put all languages below their language ID.
|
// Set this to true to put all languages below their language ID.
|
||||||
DefaultContentLanguageInSubdir bool
|
DefaultContentLanguageInSubdir bool
|
||||||
|
|
||||||
|
// Disable generation of redirect to the default language when DefaultContentLanguageInSubdir is enabled.
|
||||||
|
DisableDefaultLanguageRedirect bool
|
||||||
|
|
||||||
// Disable creation of alias redirect pages.
|
// Disable creation of alias redirect pages.
|
||||||
DisableAliases bool
|
DisableAliases bool
|
||||||
|
|
||||||
|
|
|
@ -1339,6 +1339,29 @@ Home.
|
||||||
b.Assert(len(b.H.Sites), qt.Equals, 1)
|
b.Assert(len(b.H.Sites), qt.Equals, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDisableDefaultLanguageRedirect(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
defaultContentLanguageInSubdir = true
|
||||||
|
disableDefaultLanguageRedirect = true
|
||||||
|
[languages]
|
||||||
|
[languages.en]
|
||||||
|
title = "English Title"
|
||||||
|
[languages.sv]
|
||||||
|
title = "Swedish Title"
|
||||||
|
-- layouts/index.html --
|
||||||
|
Home.
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
b := Test(t, files)
|
||||||
|
|
||||||
|
b.Assert(len(b.H.Sites), qt.Equals, 2)
|
||||||
|
b.AssertFileExists("public/index.html", false)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadConfigYamlEnvVar(t *testing.T) {
|
func TestLoadConfigYamlEnvVar(t *testing.T) {
|
||||||
defaultEnv := []string{`HUGO_OUTPUTS=home: ['json']`}
|
defaultEnv := []string{`HUGO_OUTPUTS=home: ['json']`}
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,9 @@ func (s *Site) renderAliases() error {
|
||||||
// renderMainLanguageRedirect creates a redirect to the main language home,
|
// renderMainLanguageRedirect creates a redirect to the main language home,
|
||||||
// depending on if it lives in sub folder (e.g. /en) or not.
|
// depending on if it lives in sub folder (e.g. /en) or not.
|
||||||
func (s *Site) renderMainLanguageRedirect() error {
|
func (s *Site) renderMainLanguageRedirect() error {
|
||||||
|
if s.conf.DisableDefaultLanguageRedirect {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if s.h.Conf.IsMultihost() || !(s.h.Conf.DefaultContentLanguageInSubdir() || s.h.Conf.IsMultilingual()) {
|
if s.h.Conf.IsMultihost() || !(s.h.Conf.DefaultContentLanguageInSubdir() || s.h.Conf.IsMultilingual()) {
|
||||||
// No need for a redirect
|
// No need for a redirect
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue