]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Add hugo.IsMultiHost
authorrazonyang <razonyang@gmail.com>
Thu, 29 Feb 2024 15:58:57 +0000 (23:58 +0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 7 Mar 2024 13:04:41 +0000 (14:04 +0100)
common/hugo/hugo.go
common/hugo/hugo_test.go
resources/page/page_matcher_test.go
testscripts/commands/hugo_is_multihost.txt [new file with mode: 0644]

index be43e2a388225ede8a99b6575688a8d8cdf21c4c..4ead647b8f5790d6e0eb0fe643d9667c6ac07069 100644 (file)
@@ -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.
index e252dffbe927c3f790b10233bab929416d7e172e..e76d80000accad42f14bf419dba2d0c6c2995877 100644 (file)
@@ -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
+}
index e659eb3b5d0e8bfc986ead6b840619518ad66518..21f6891d76cf149874bcfd4ff4d94758f423e61a 100644 (file)
@@ -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 (file)
index 0000000..a1147cd
--- /dev/null
@@ -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 }}