Skip to content

Commit

Permalink
common/hugo: Rename IsMultiHost and IsMultiLingual
Browse files Browse the repository at this point in the history
hugo.IsMultiHost => hugo.IsMultihost
hugo.IsMultiLingual => hugo.IsMultilingual

Closes #12232
  • Loading branch information
jmooring authored and bep committed Mar 13, 2024
1 parent 4f92f94 commit dc6a292
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 62 deletions.
13 changes: 6 additions & 7 deletions commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,9 @@ func (c *serverCommand) setBaseURLsInConfig() error {
}
return c.withConfE(func(conf *commonConfig) error {
for i, language := range conf.configs.Languages {
isMultiHost := conf.configs.IsMultihost
isMultihost := conf.configs.IsMultihost
var serverPort int
if isMultiHost {
if isMultihost {
serverPort = c.serverPorts[i].p
} else {
serverPort = c.serverPorts[0].p
Expand Down Expand Up @@ -737,9 +737,9 @@ func (c *serverCommand) createServerPorts(cd *simplecobra.Commandeer) error {
flags := cd.CobraCommand.Flags()
var cerr error
c.withConf(func(conf *commonConfig) {
isMultiHost := conf.configs.IsMultihost
isMultihost := conf.configs.IsMultihost
c.serverPorts = make([]serverPortListener, 1)
if isMultiHost {
if isMultihost {
if !c.serverAppend {
cerr = errors.New("--appendPort=false not supported when in multihost mode")
return
Expand Down Expand Up @@ -852,7 +852,7 @@ func (c *serverCommand) serve() error {
h *hugolib.HugoSites
)
err := c.withConfE(func(conf *commonConfig) error {
isMultiHost := conf.configs.IsMultihost
isMultihost := conf.configs.IsMultihost
var err error
h, err = c.r.HugFromConfig(conf)
if err != nil {
Expand All @@ -862,7 +862,7 @@ func (c *serverCommand) serve() error {
// We need the server to share the same logger as the Hugo build (for error counts etc.)
c.r.logger = h.Log

if isMultiHost {
if isMultihost {
for _, l := range conf.configs.ConfigLangs() {
baseURLs = append(baseURLs, l.BaseURL())
roots = append(roots, l.Language().Lang)
Expand Down Expand Up @@ -1005,7 +1005,6 @@ func (c *serverCommand) serve() error {
}
}
}()

if err != nil {
c.r.Println("Error:", err)
}
Expand Down
16 changes: 11 additions & 5 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ func (i HugoInfo) Deps() []*Dependency {
return i.deps
}

// IsMultiHost reports whether each configured language has a unique baseURL.
// Deprecated: Use hugo.IsMultihost instead.
func (i HugoInfo) IsMultiHost() bool {
Deprecate("hugo.IsMultiHost", "Use hugo.IsMultihost instead.", "v0.124.0")
return i.conf.IsMultihost()
}

// IsMultiLingual reports whether there are two or more configured languages.
func (i HugoInfo) IsMultiLingual() bool {
return i.conf.IsMultiLingual()
// IsMultihost reports whether each configured language has a unique baseURL.
func (i HugoInfo) IsMultihost() bool {
return i.conf.IsMultihost()
}

// IsMultilingual reports whether there are two or more configured languages.
func (i HugoInfo) IsMultilingual() bool {
return i.conf.IsMultilingual()
}

// ConfigProvider represents the config options that are relevant for HugoInfo.
Expand All @@ -127,7 +133,7 @@ type ConfigProvider interface {
Running() bool
WorkingDir() string
IsMultihost() bool
IsMultiLingual() bool
IsMultilingual() bool
}

// NewInfo creates a new Hugo Info object.
Expand Down
6 changes: 3 additions & 3 deletions common/hugo/hugo_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/gohugoio/hugo/hugolib"
)

func TestIsMultiLingualAndIsMultiHost(t *testing.T) {
func TestIsMultilingualAndIsMultihost(t *testing.T) {
t.Parallel()

files := `
Expand All @@ -36,8 +36,8 @@ baseURL = 'https://en.example.org/'
title: home
---
-- layouts/index.html --
multilingual={{ hugo.IsMultiLingual }}
multihost={{ hugo.IsMultiHost }}
multilingual={{ hugo.IsMultilingual }}
multihost={{ hugo.IsMultihost }}
`

b := hugolib.Test(t, files)
Expand Down
2 changes: 1 addition & 1 deletion common/hugo/hugo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ func (c testConfig) IsMultihost() bool {
return c.multihost
}

func (c testConfig) IsMultiLingual() bool {
func (c testConfig) IsMultilingual() bool {
return c.multilingual
}
8 changes: 4 additions & 4 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
langConfigMap := make(map[string]*Config)

languagesConfig := cfg.GetStringMap("languages")
var isMultiHost bool
var isMultihost bool

if err := all.CompileConfig(logger); err != nil {
return nil, err
Expand Down Expand Up @@ -863,7 +863,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
}
if kk == "baseurl" {
// baseURL configure don the language level is a multihost setup.
isMultiHost = true
isMultihost = true
}
mergedConfig.Set(kk, vv)
rootv := cfg.Get(kk)
Expand Down Expand Up @@ -913,7 +913,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
}

// Adjust Goldmark config defaults for multilingual, single-host sites.
if len(languagesConfig) > 1 && !isMultiHost && !clone.Markup.Goldmark.DuplicateResourceFiles {
if len(languagesConfig) > 1 && !isMultihost && !clone.Markup.Goldmark.DuplicateResourceFiles {
if !clone.Markup.Goldmark.DuplicateResourceFiles {
if clone.Markup.Goldmark.RenderHooks.Link.EnableDefault == nil {
clone.Markup.Goldmark.RenderHooks.Link.EnableDefault = types.NewBool(true)
Expand Down Expand Up @@ -943,7 +943,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
Base: all,
LanguageConfigMap: langConfigMap,
LoadingInfo: res,
IsMultihost: isMultiHost,
IsMultihost: isMultihost,
}

return cm, nil
Expand Down
4 changes: 2 additions & 2 deletions config/allconfig/configlanguage.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c ConfigLanguage) LanguagePrefix() string {
return c.Language().Lang
}

if !c.IsMultiLingual() || c.DefaultContentLanguage() == c.Language().Lang {
if !c.IsMultilingual() || c.DefaultContentLanguage() == c.Language().Lang {
return ""
}
return c.Language().Lang
Expand All @@ -78,7 +78,7 @@ func (c ConfigLanguage) FastRenderMode() bool {
return c.config.Internal.FastRenderMode
}

func (c ConfigLanguage) IsMultiLingual() bool {
func (c ConfigLanguage) IsMultilingual() bool {
return len(c.m.Languages) > 1
}

Expand Down
2 changes: 1 addition & 1 deletion config/configProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AllProvider interface {
PathParser() *paths.PathParser
Environment() string
IsMultihost() bool
IsMultiLingual() bool
IsMultilingual() bool
NoBuildLock() bool
BaseConfig() BaseConfig
Dirs() CommonDirs
Expand Down
42 changes: 21 additions & 21 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ func TestLoadConfigFromThemeDir(t *testing.T) {
theme = "test-theme"
[params]
m1 = "mv1"
m1 = "mv1"
`

themeConfig := `
[params]
t1 = "tv1"
t1 = "tv1"
t2 = "tv2"
`

Expand Down Expand Up @@ -885,9 +885,9 @@ ThisIsAParam: {{ site.Params.thisIsAParam }}
).BuildE()

b.Assert(err, qt.IsNil)
b.AssertFileContent("public/index.html", `
b.AssertFileContent("public/index.html", `
MyParam: enParamValue
ThisIsAParam: thisIsAParamValue
ThisIsAParam: thisIsAParamValue
`)
}

Expand Down Expand Up @@ -919,7 +919,7 @@ title: "My Swedish Section"
-- layouts/index.html --
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
{{ 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 }}|Language string: {{ .Language }}|Languages: {{ .Languages }}
{{ $i }}|AllPages: {{ len .AllPages }}|Sections: {{ if .Sections }}true{{ end }}| Author: {{ .Authors }}|BuildDrafts: {{ .BuildDrafts }}|IsMultilingual: {{ .IsMultiLingual }}|Param: {{ .Language.Params.myparam }}|Language string: {{ .Language }}|Languages: {{ .Languages }}
{{ end }}
Expand All @@ -939,9 +939,9 @@ LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Lang
b.AssertFileContent("public/index.html", `
AllPages: 4|
Sections: true|
Param: enParamValue
Param: enParamValue
IsMultiLingual: true
Param: enParamValue
Param: enParamValue
IsMultilingual: true
LanguageCode: true|en-US|
`)

Expand Down Expand Up @@ -1062,7 +1062,7 @@ Home
).BuildE()

b.Assert(err, qt.IsNil)
b.AssertFileContent("public/index.html", `
b.AssertFileContent("public/index.html", `
Home
`)

Expand Down Expand Up @@ -1095,7 +1095,7 @@ HTML.
HTACCESS.
`
b := Test(t, files)

Expand All @@ -1111,7 +1111,7 @@ languageCode = "en-US"
-- layouts/index.html --
LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
`
b := Test(t, files)

Expand All @@ -1137,7 +1137,7 @@ suffixes = ["bar"]
-- layouts/index.html --
Home.
`
b := Test(t, files)

Expand All @@ -1164,8 +1164,8 @@ func TestConfigMiscPanics(t *testing.T) {
params:
-- layouts/index.html --
Foo: {{ site.Params.foo }}|
`
b := Test(t, files)

Expand All @@ -1188,8 +1188,8 @@ defaultContentLanguage = "en"
weight = 1
-- layouts/index.html --
Foo: {{ site.Params.foo }}|
`
b, err := NewIntegrationTestBuilder(
IntegrationTestConfig{
Expand All @@ -1215,8 +1215,8 @@ languageCode = "en"
languageName = "English"
weight = 1
`
b, err := NewIntegrationTestBuilder(
IntegrationTestConfig{
Expand All @@ -1241,7 +1241,7 @@ contentDir = "mycontent"
-- layouts/index.html --
Home.
`
b := Test(t, files)

Expand Down Expand Up @@ -1343,7 +1343,7 @@ disabled = true
-- layouts/index.html --
Home.
`
b := Test(t, files)

Expand Down Expand Up @@ -1438,7 +1438,7 @@ home = ["html"]
-- hugo.toml --
baseURL = "https://example.com"
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT", "page", "section"]
`

runVariant(t, files, nil)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ func (sa *sitePagesAssembler) addStandalonePages() error {

if sitemapEnabled {
addStandalone("/_sitemap", kinds.KindSitemap, output.SitemapFormat)
skipSitemapIndex := s.Conf.IsMultihost() || !(s.Conf.DefaultContentLanguageInSubdir() || s.Conf.IsMultiLingual())
skipSitemapIndex := s.Conf.IsMultihost() || !(s.Conf.DefaultContentLanguageInSubdir() || s.Conf.IsMultilingual())

if !skipSitemapIndex {
addStandalone("/_sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
Expand Down
4 changes: 2 additions & 2 deletions hugolib/filesystems/basefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestStaticFs(t *testing.T) {
checkFileContent(sfs, "f2.txt", c, "Hugo Themes Still Rocks!")
}

func TestStaticFsMultiHost(t *testing.T) {
func TestStaticFsMultihost(t *testing.T) {
c := qt.New(t)
v := config.New()
workDir := "mywork"
Expand Down Expand Up @@ -537,7 +537,7 @@ SCSS Match: {{ with resources.Match "**.scss" }}{{ . | len }}|{{ range .}}{{ .Re

b := hugolib.Test(t, files)

b.AssertFileContent("public/index.html", `
b.AssertFileContent("public/index.html", `
SCSS: /scss/app.scss|body { color: blue; }|
SCSS Match: 2|
`)
Expand Down
2 changes: 1 addition & 1 deletion hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (h *HugoSites) pickOneAndLogTheRest(errors []error) error {
return errors[i]
}

func (h *HugoSites) isMultiLingual() bool {
func (h *HugoSites) isMultilingual() bool {
return len(h.Sites) > 1
}

Expand Down
4 changes: 2 additions & 2 deletions hugolib/hugo_sites_multihost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ robots|{{ site.Language.Lang }}
404|{{ site.Language.Lang }}
`

b := Test(t, files)

b.Assert(b.H.Conf.IsMultiLingual(), qt.Equals, true)
b.Assert(b.H.Conf.IsMultilingual(), qt.Equals, true)
b.Assert(b.H.Conf.IsMultihost(), qt.Equals, true)

// helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout)
Expand Down
3 changes: 1 addition & 2 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFor
ref = filepath.ToSlash(ref)

refURL, err = url.Parse(ref)

if err != nil {
return s.notFoundURL, err
}
Expand Down Expand Up @@ -681,7 +680,7 @@ func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
return ""
}

if s.h.Conf.IsMultiLingual() && alwaysInSubDir {
if s.h.Conf.IsMultilingual() && alwaysInSubDir {
return s.Language().Lang
}

Expand Down

0 comments on commit dc6a292

Please sign in to comment.