From 1f48b717c7f1bb9ecdbf8a7f50cbcdc5cf1dcc0a Mon Sep 17 00:00:00 2001 From: razonyang Date: Thu, 29 Feb 2024 23:58:57 +0800 Subject: [PATCH] Add hugo.IsMultiHost --- common/hugo/hugo.go | 6 ++++++ common/hugo/hugo_test.go | 5 +++++ resources/page/page_matcher_test.go | 5 +++++ testscripts/commands/hugo_is_multihost.txt | 13 +++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 testscripts/commands/hugo_is_multihost.txt diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index be43e2a38..4ead647b8 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -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. diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go index e252dffbe..e76d80000 100644 --- a/common/hugo/hugo_test.go +++ b/common/hugo/hugo_test.go @@ -68,6 +68,7 @@ type testConfig struct { environment string running bool workingDir string + multihost bool } func (c testConfig) Environment() string { @@ -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 +} diff --git a/resources/page/page_matcher_test.go b/resources/page/page_matcher_test.go index e659eb3b5..21f6891d7 100644 --- a/resources/page/page_matcher_test.go +++ b/resources/page/page_matcher_test.go @@ -160,6 +160,7 @@ type testConfig struct { environment string running bool workingDir string + multihost bool } func (c testConfig) Environment() string { @@ -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) diff --git a/testscripts/commands/hugo_is_multihost.txt b/testscripts/commands/hugo_is_multihost.txt new file mode 100644 index 000000000..a1147cd73 --- /dev/null +++ b/testscripts/commands/hugo_is_multihost.txt @@ -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 }}