Skip to content

Commit

Permalink
Add hugo.IsMultiHost
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored and bep committed Mar 7, 2024
1 parent ada3fce commit 1f48b71
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,17 @@ func (i HugoInfo) Deps() []*Dependency {
return i.deps
}

// IsMultiHost reports whether each configured language has a unique baseURL.
func (i HugoInfo) IsMultiHost() bool {
return i.conf.IsMultihost()
}

// ConfigProvider represents the config options that are relevant for HugoInfo.
type ConfigProvider interface {
Environment() string
Running() bool
WorkingDir() string
IsMultihost() bool
}

// NewInfo creates a new Hugo Info object.
Expand Down
5 changes: 5 additions & 0 deletions common/hugo/hugo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type testConfig struct {
environment string
running bool
workingDir string
multihost bool
}

func (c testConfig) Environment() string {
Expand All @@ -81,3 +82,7 @@ func (c testConfig) Running() bool {
func (c testConfig) WorkingDir() string {
return c.workingDir
}

func (c testConfig) IsMultihost() bool {
return c.multihost
}
5 changes: 5 additions & 0 deletions resources/page/page_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ type testConfig struct {
environment string
running bool
workingDir string
multihost bool
}

func (c testConfig) Environment() string {
Expand All @@ -174,6 +175,10 @@ func (c testConfig) WorkingDir() string {
return c.workingDir
}

func (c testConfig) IsMultihost() bool {
return c.multihost
}

func TestIsGlobWithExtension(t *testing.T) {
c := qt.New(t)

Expand Down
13 changes: 13 additions & 0 deletions testscripts/commands/hugo_is_multihost.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
hugo

stdout 'IsMultiHost: true'

-- hugo.toml --
title = "Hugo IsMultiHost Test"
[languages.en]
baseURL = "https://example.org"
[languages.zh]
baseURL = "https://zh.example.org"

-- layouts/index.html --
{{ warnf "IsMultiHost: %v" hugo.IsMultiHost }}

0 comments on commit 1f48b71

Please sign in to comment.