mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
common/hugo: Rename IsMultiHost and IsMultiLingual
hugo.IsMultiHost => hugo.IsMultihost hugo.IsMultiLingual => hugo.IsMultilingual Closes #12232
This commit is contained in:
parent
4f92f949ea
commit
dc6a292133
18 changed files with 66 additions and 62 deletions
|
@ -617,9 +617,9 @@ func (c *serverCommand) setBaseURLsInConfig() error {
|
||||||
}
|
}
|
||||||
return c.withConfE(func(conf *commonConfig) error {
|
return c.withConfE(func(conf *commonConfig) error {
|
||||||
for i, language := range conf.configs.Languages {
|
for i, language := range conf.configs.Languages {
|
||||||
isMultiHost := conf.configs.IsMultihost
|
isMultihost := conf.configs.IsMultihost
|
||||||
var serverPort int
|
var serverPort int
|
||||||
if isMultiHost {
|
if isMultihost {
|
||||||
serverPort = c.serverPorts[i].p
|
serverPort = c.serverPorts[i].p
|
||||||
} else {
|
} else {
|
||||||
serverPort = c.serverPorts[0].p
|
serverPort = c.serverPorts[0].p
|
||||||
|
@ -737,9 +737,9 @@ func (c *serverCommand) createServerPorts(cd *simplecobra.Commandeer) error {
|
||||||
flags := cd.CobraCommand.Flags()
|
flags := cd.CobraCommand.Flags()
|
||||||
var cerr error
|
var cerr error
|
||||||
c.withConf(func(conf *commonConfig) {
|
c.withConf(func(conf *commonConfig) {
|
||||||
isMultiHost := conf.configs.IsMultihost
|
isMultihost := conf.configs.IsMultihost
|
||||||
c.serverPorts = make([]serverPortListener, 1)
|
c.serverPorts = make([]serverPortListener, 1)
|
||||||
if isMultiHost {
|
if isMultihost {
|
||||||
if !c.serverAppend {
|
if !c.serverAppend {
|
||||||
cerr = errors.New("--appendPort=false not supported when in multihost mode")
|
cerr = errors.New("--appendPort=false not supported when in multihost mode")
|
||||||
return
|
return
|
||||||
|
@ -852,7 +852,7 @@ func (c *serverCommand) serve() error {
|
||||||
h *hugolib.HugoSites
|
h *hugolib.HugoSites
|
||||||
)
|
)
|
||||||
err := c.withConfE(func(conf *commonConfig) error {
|
err := c.withConfE(func(conf *commonConfig) error {
|
||||||
isMultiHost := conf.configs.IsMultihost
|
isMultihost := conf.configs.IsMultihost
|
||||||
var err error
|
var err error
|
||||||
h, err = c.r.HugFromConfig(conf)
|
h, err = c.r.HugFromConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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.)
|
// We need the server to share the same logger as the Hugo build (for error counts etc.)
|
||||||
c.r.logger = h.Log
|
c.r.logger = h.Log
|
||||||
|
|
||||||
if isMultiHost {
|
if isMultihost {
|
||||||
for _, l := range conf.configs.ConfigLangs() {
|
for _, l := range conf.configs.ConfigLangs() {
|
||||||
baseURLs = append(baseURLs, l.BaseURL())
|
baseURLs = append(baseURLs, l.BaseURL())
|
||||||
roots = append(roots, l.Language().Lang)
|
roots = append(roots, l.Language().Lang)
|
||||||
|
@ -1005,7 +1005,6 @@ func (c *serverCommand) serve() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.r.Println("Error:", err)
|
c.r.Println("Error:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,14 +111,20 @@ func (i HugoInfo) Deps() []*Dependency {
|
||||||
return i.deps
|
return i.deps
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMultiHost reports whether each configured language has a unique baseURL.
|
// Deprecated: Use hugo.IsMultihost instead.
|
||||||
func (i HugoInfo) IsMultiHost() bool {
|
func (i HugoInfo) IsMultiHost() bool {
|
||||||
|
Deprecate("hugo.IsMultiHost", "Use hugo.IsMultihost instead.", "v0.124.0")
|
||||||
return i.conf.IsMultihost()
|
return i.conf.IsMultihost()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMultiLingual reports whether there are two or more configured languages.
|
// IsMultihost reports whether each configured language has a unique baseURL.
|
||||||
func (i HugoInfo) IsMultiLingual() bool {
|
func (i HugoInfo) IsMultihost() bool {
|
||||||
return i.conf.IsMultiLingual()
|
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.
|
// ConfigProvider represents the config options that are relevant for HugoInfo.
|
||||||
|
@ -127,7 +133,7 @@ type ConfigProvider interface {
|
||||||
Running() bool
|
Running() bool
|
||||||
WorkingDir() string
|
WorkingDir() string
|
||||||
IsMultihost() bool
|
IsMultihost() bool
|
||||||
IsMultiLingual() bool
|
IsMultilingual() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInfo creates a new Hugo Info object.
|
// NewInfo creates a new Hugo Info object.
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsMultiLingualAndIsMultiHost(t *testing.T) {
|
func TestIsMultilingualAndIsMultihost(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
files := `
|
files := `
|
||||||
|
@ -36,8 +36,8 @@ baseURL = 'https://en.example.org/'
|
||||||
title: home
|
title: home
|
||||||
---
|
---
|
||||||
-- layouts/index.html --
|
-- layouts/index.html --
|
||||||
multilingual={{ hugo.IsMultiLingual }}
|
multilingual={{ hugo.IsMultilingual }}
|
||||||
multihost={{ hugo.IsMultiHost }}
|
multihost={{ hugo.IsMultihost }}
|
||||||
`
|
`
|
||||||
|
|
||||||
b := hugolib.Test(t, files)
|
b := hugolib.Test(t, files)
|
||||||
|
|
|
@ -88,6 +88,6 @@ func (c testConfig) IsMultihost() bool {
|
||||||
return c.multihost
|
return c.multihost
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c testConfig) IsMultiLingual() bool {
|
func (c testConfig) IsMultilingual() bool {
|
||||||
return c.multilingual
|
return c.multilingual
|
||||||
}
|
}
|
||||||
|
|
|
@ -826,7 +826,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||||
langConfigMap := make(map[string]*Config)
|
langConfigMap := make(map[string]*Config)
|
||||||
|
|
||||||
languagesConfig := cfg.GetStringMap("languages")
|
languagesConfig := cfg.GetStringMap("languages")
|
||||||
var isMultiHost bool
|
var isMultihost bool
|
||||||
|
|
||||||
if err := all.CompileConfig(logger); err != nil {
|
if err := all.CompileConfig(logger); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -863,7 +863,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||||
}
|
}
|
||||||
if kk == "baseurl" {
|
if kk == "baseurl" {
|
||||||
// baseURL configure don the language level is a multihost setup.
|
// baseURL configure don the language level is a multihost setup.
|
||||||
isMultiHost = true
|
isMultihost = true
|
||||||
}
|
}
|
||||||
mergedConfig.Set(kk, vv)
|
mergedConfig.Set(kk, vv)
|
||||||
rootv := cfg.Get(kk)
|
rootv := cfg.Get(kk)
|
||||||
|
@ -913,7 +913,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust Goldmark config defaults for multilingual, single-host sites.
|
// 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.DuplicateResourceFiles {
|
||||||
if clone.Markup.Goldmark.RenderHooks.Link.EnableDefault == nil {
|
if clone.Markup.Goldmark.RenderHooks.Link.EnableDefault == nil {
|
||||||
clone.Markup.Goldmark.RenderHooks.Link.EnableDefault = types.NewBool(true)
|
clone.Markup.Goldmark.RenderHooks.Link.EnableDefault = types.NewBool(true)
|
||||||
|
@ -943,7 +943,7 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||||
Base: all,
|
Base: all,
|
||||||
LanguageConfigMap: langConfigMap,
|
LanguageConfigMap: langConfigMap,
|
||||||
LoadingInfo: res,
|
LoadingInfo: res,
|
||||||
IsMultihost: isMultiHost,
|
IsMultihost: isMultihost,
|
||||||
}
|
}
|
||||||
|
|
||||||
return cm, nil
|
return cm, nil
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (c ConfigLanguage) LanguagePrefix() string {
|
||||||
return c.Language().Lang
|
return c.Language().Lang
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.IsMultiLingual() || c.DefaultContentLanguage() == c.Language().Lang {
|
if !c.IsMultilingual() || c.DefaultContentLanguage() == c.Language().Lang {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return c.Language().Lang
|
return c.Language().Lang
|
||||||
|
@ -78,7 +78,7 @@ func (c ConfigLanguage) FastRenderMode() bool {
|
||||||
return c.config.Internal.FastRenderMode
|
return c.config.Internal.FastRenderMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ConfigLanguage) IsMultiLingual() bool {
|
func (c ConfigLanguage) IsMultilingual() bool {
|
||||||
return len(c.m.Languages) > 1
|
return len(c.m.Languages) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ type AllProvider interface {
|
||||||
PathParser() *paths.PathParser
|
PathParser() *paths.PathParser
|
||||||
Environment() string
|
Environment() string
|
||||||
IsMultihost() bool
|
IsMultihost() bool
|
||||||
IsMultiLingual() bool
|
IsMultilingual() bool
|
||||||
NoBuildLock() bool
|
NoBuildLock() bool
|
||||||
BaseConfig() BaseConfig
|
BaseConfig() BaseConfig
|
||||||
Dirs() CommonDirs
|
Dirs() CommonDirs
|
||||||
|
|
|
@ -919,7 +919,7 @@ title: "My Swedish Section"
|
||||||
-- layouts/index.html --
|
-- layouts/index.html --
|
||||||
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
||||||
{{ range $i, $e := (slice site .Site) }}
|
{{ 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 }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ AllPages: 4|
|
||||||
Sections: true|
|
Sections: true|
|
||||||
Param: enParamValue
|
Param: enParamValue
|
||||||
Param: enParamValue
|
Param: enParamValue
|
||||||
IsMultiLingual: true
|
IsMultilingual: true
|
||||||
LanguageCode: true|en-US|
|
LanguageCode: true|en-US|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
|
@ -1778,7 +1778,7 @@ func (sa *sitePagesAssembler) addStandalonePages() error {
|
||||||
|
|
||||||
if sitemapEnabled {
|
if sitemapEnabled {
|
||||||
addStandalone("/_sitemap", kinds.KindSitemap, output.SitemapFormat)
|
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 {
|
if !skipSitemapIndex {
|
||||||
addStandalone("/_sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
|
addStandalone("/_sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
|
||||||
|
|
|
@ -315,7 +315,7 @@ func TestStaticFs(t *testing.T) {
|
||||||
checkFileContent(sfs, "f2.txt", c, "Hugo Themes Still Rocks!")
|
checkFileContent(sfs, "f2.txt", c, "Hugo Themes Still Rocks!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStaticFsMultiHost(t *testing.T) {
|
func TestStaticFsMultihost(t *testing.T) {
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
v := config.New()
|
v := config.New()
|
||||||
workDir := "mywork"
|
workDir := "mywork"
|
||||||
|
|
|
@ -269,7 +269,7 @@ func (h *HugoSites) pickOneAndLogTheRest(errors []error) error {
|
||||||
return errors[i]
|
return errors[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) isMultiLingual() bool {
|
func (h *HugoSites) isMultilingual() bool {
|
||||||
return len(h.Sites) > 1
|
return len(h.Sites) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ robots|{{ site.Language.Lang }}
|
||||||
|
|
||||||
b := Test(t, files)
|
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)
|
b.Assert(b.H.Conf.IsMultihost(), qt.Equals, true)
|
||||||
|
|
||||||
// helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout)
|
// helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout)
|
||||||
|
|
|
@ -297,7 +297,6 @@ func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFor
|
||||||
ref = filepath.ToSlash(ref)
|
ref = filepath.ToSlash(ref)
|
||||||
|
|
||||||
refURL, err = url.Parse(ref)
|
refURL, err = url.Parse(ref)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.notFoundURL, err
|
return s.notFoundURL, err
|
||||||
}
|
}
|
||||||
|
@ -681,7 +680,7 @@ func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.h.Conf.IsMultiLingual() && alwaysInSubDir {
|
if s.h.Conf.IsMultilingual() && alwaysInSubDir {
|
||||||
return s.Language().Lang
|
return s.Language().Lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -484,10 +484,10 @@ func (s *Site) BuildDrafts() bool {
|
||||||
return s.conf.BuildDrafts
|
return s.conf.BuildDrafts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use hugo.IsMultiLingual instead.
|
// Deprecated: Use hugo.IsMultilingual instead.
|
||||||
func (s *Site) IsMultiLingual() bool {
|
func (s *Site) IsMultiLingual() bool {
|
||||||
hugo.Deprecate(".Site.IsMultiLingual", "Use hugo.IsMultiLingual instead.", "v0.124.0")
|
hugo.Deprecate(".Site.IsMultiLingual", "Use hugo.IsMultilingual instead.", "v0.124.0")
|
||||||
return s.h.isMultiLingual()
|
return s.h.isMultilingual()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) LanguagePrefix() string {
|
func (s *Site) LanguagePrefix() string {
|
||||||
|
|
|
@ -334,7 +334,7 @@ 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.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
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ func ApplyProjectConfigDefaults(mod Module, cfgs ...config.AllProvider) error {
|
||||||
|
|
||||||
first := cfgs[0]
|
first := cfgs[0]
|
||||||
dirsBase := first.DirsBase()
|
dirsBase := first.DirsBase()
|
||||||
isMultiHost := first.IsMultihost()
|
isMultihost := first.IsMultihost()
|
||||||
|
|
||||||
for i, cfg := range cfgs {
|
for i, cfg := range cfgs {
|
||||||
dirs := cfg.Dirs()
|
dirs := cfg.Dirs()
|
||||||
|
@ -113,7 +113,7 @@ func ApplyProjectConfigDefaults(mod Module, cfgs ...config.AllProvider) error {
|
||||||
dir = dirs.AssetDir
|
dir = dirs.AssetDir
|
||||||
case files.ComponentFolderStatic:
|
case files.ComponentFolderStatic:
|
||||||
// For static dirs, we only care about the language in multihost setups.
|
// For static dirs, we only care about the language in multihost setups.
|
||||||
dropLang = !isMultiHost
|
dropLang = !isMultihost
|
||||||
}
|
}
|
||||||
|
|
||||||
var perLang bool
|
var perLang bool
|
||||||
|
|
|
@ -180,7 +180,7 @@ func (c testConfig) IsMultihost() bool {
|
||||||
return c.multihost
|
return c.multihost
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c testConfig) IsMultiLingual() bool {
|
func (c testConfig) IsMultilingual() bool {
|
||||||
return c.multilingual
|
return c.multilingual
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ type Site interface {
|
||||||
// BuildDrafts is deprecated and will be removed in a future release.
|
// BuildDrafts is deprecated and will be removed in a future release.
|
||||||
BuildDrafts() bool
|
BuildDrafts() bool
|
||||||
|
|
||||||
// Deprecated: Use hugo.IsMultiLingual instead.
|
// Deprecated: Use hugo.IsMultilingual instead.
|
||||||
IsMultiLingual() bool
|
IsMultiLingual() bool
|
||||||
|
|
||||||
// LanguagePrefix returns the language prefix for this site.
|
// LanguagePrefix returns the language prefix for this site.
|
||||||
|
@ -292,7 +292,7 @@ func (s *siteWrapper) BuildDrafts() bool {
|
||||||
return s.s.BuildDrafts()
|
return s.s.BuildDrafts()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use hugo.IsMultiLingual instead.
|
// Deprecated: Use hugo.IsMultilingual instead.
|
||||||
func (s *siteWrapper) IsMultiLingual() bool {
|
func (s *siteWrapper) IsMultiLingual() bool {
|
||||||
return s.s.IsMultiLingual()
|
return s.s.IsMultiLingual()
|
||||||
}
|
}
|
||||||
|
@ -453,7 +453,7 @@ func (s testSite) BuildDrafts() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use hugo.IsMultiLingual instead.
|
// Deprecated: Use hugo.IsMultilingual instead.
|
||||||
func (s testSite) IsMultiLingual() bool {
|
func (s testSite) IsMultiLingual() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue