Skip to content

Commit 4f92f94

Browse files
jmooringbep
authored andcommitted
hugolib: Deprecate .Site.MultiLingual in favor of hugo.IsMultiLingual
Closes gohugoio#12224
1 parent d24ffdd commit 4f92f94

File tree

9 files changed

+129
-45
lines changed

9 files changed

+129
-45
lines changed

common/hugo/hugo.go

+6
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,18 @@ func (i HugoInfo) IsMultiHost() bool {
116116
return i.conf.IsMultihost()
117117
}
118118

119+
// IsMultiLingual reports whether there are two or more configured languages.
120+
func (i HugoInfo) IsMultiLingual() bool {
121+
return i.conf.IsMultiLingual()
122+
}
123+
119124
// ConfigProvider represents the config options that are relevant for HugoInfo.
120125
type ConfigProvider interface {
121126
Environment() string
122127
Running() bool
123128
WorkingDir() string
124129
IsMultihost() bool
130+
IsMultiLingual() bool
125131
}
126132

127133
// NewInfo creates a new Hugo Info object.

common/hugo/hugo_integration_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2024 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package hugo_test
15+
16+
import (
17+
"strings"
18+
"testing"
19+
20+
"github.com/gohugoio/hugo/hugolib"
21+
)
22+
23+
func TestIsMultiLingualAndIsMultiHost(t *testing.T) {
24+
t.Parallel()
25+
26+
files := `
27+
-- hugo.toml --
28+
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
29+
defaultContentLanguageInSubdir = true
30+
[languages.de]
31+
baseURL = 'https://de.example.org/'
32+
[languages.en]
33+
baseURL = 'https://en.example.org/'
34+
-- content/_index.md --
35+
---
36+
title: home
37+
---
38+
-- layouts/index.html --
39+
multilingual={{ hugo.IsMultiLingual }}
40+
multihost={{ hugo.IsMultiHost }}
41+
`
42+
43+
b := hugolib.Test(t, files)
44+
45+
b.AssertFileContent("public/de/index.html",
46+
"multilingual=true",
47+
"multihost=true",
48+
)
49+
b.AssertFileContent("public/en/index.html",
50+
"multilingual=true",
51+
"multihost=true",
52+
)
53+
54+
files = strings.ReplaceAll(files, "baseURL = 'https://de.example.org/'", "")
55+
files = strings.ReplaceAll(files, "baseURL = 'https://en.example.org/'", "")
56+
57+
b = hugolib.Test(t, files)
58+
59+
b.AssertFileContent("public/de/index.html",
60+
"multilingual=true",
61+
"multihost=false",
62+
)
63+
b.AssertFileContent("public/en/index.html",
64+
"multilingual=true",
65+
"multihost=false",
66+
)
67+
68+
files = strings.ReplaceAll(files, "[languages.de]", "")
69+
files = strings.ReplaceAll(files, "[languages.en]", "")
70+
71+
b = hugolib.Test(t, files)
72+
73+
b.AssertFileContent("public/en/index.html",
74+
"multilingual=false",
75+
"multihost=false",
76+
)
77+
}

common/hugo/hugo_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ func TestDeprecationLogLevelFromVersion(t *testing.T) {
6565
}
6666

6767
type testConfig struct {
68-
environment string
69-
running bool
70-
workingDir string
71-
multihost bool
68+
environment string
69+
running bool
70+
workingDir string
71+
multihost bool
72+
multilingual bool
7273
}
7374

7475
func (c testConfig) Environment() string {
@@ -86,3 +87,7 @@ func (c testConfig) WorkingDir() string {
8687
func (c testConfig) IsMultihost() bool {
8788
return c.multihost
8889
}
90+
91+
func (c testConfig) IsMultiLingual() bool {
92+
return c.multilingual
93+
}

hugolib/page_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ date: 2012-01-12
578578
b.Assert(s.getPageOldVersion("/with-index-no-date").Date().IsZero(), qt.Equals, true)
579579
checkDate(s.getPageOldVersion("/with-index-date"), 2018)
580580

581-
b.Assert(s.Site().LastChange().Year(), qt.Equals, 2018)
581+
b.Assert(s.Site().Lastmod().Year(), qt.Equals, 2018)
582582
}
583583

584584
func TestCreateNewPage(t *testing.T) {
@@ -773,7 +773,7 @@ func TestSummaryManualSplit(t *testing.T) {
773773
title: Simple
774774
---
775775
This is **summary**.
776-
<!--more-->
776+
<!--more-->
777777
This is **content**.
778778
-- layouts/_default/single.html --
779779
Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|

hugolib/site_new.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ func newHugoSites(cfg deps.DepsCfg, d *deps.Deps, pageTrees *pageTrees, sites []
361361
return h, nil
362362
}
363363

364-
// Returns true if we're running in a server.
365-
// Deprecated: use hugo.IsServer instead
364+
// Deprecated: Use hugo.IsServer instead.
366365
func (s *Site) IsServer() bool {
367366
hugo.Deprecate(".Site.IsServer", "Use hugo.IsServer instead.", "v0.120.0")
368367
return s.conf.Internal.Running
@@ -382,8 +381,9 @@ func (s *Site) Copyright() string {
382381
return s.conf.Copyright
383382
}
384383

384+
// Deprecated: Use .Site.Home.OutputFormats.Get "rss" instead.
385385
func (s *Site) RSSLink() template.URL {
386-
hugo.Deprecate("Site.RSSLink", "Use the Output Format's Permalink method instead, e.g. .OutputFormats.Get \"RSS\".Permalink", "v0.114.0")
386+
hugo.Deprecate(".Site.RSSLink", "Use the Output Format's Permalink method instead, e.g. .OutputFormats.Get \"RSS\".Permalink", "v0.114.0")
387387
rssOutputFormat := s.home.OutputFormats().Get("rss")
388388
return template.URL(rssOutputFormat.Permalink())
389389
}
@@ -431,9 +431,9 @@ func (s *Site) BaseURL() string {
431431
return s.conf.C.BaseURL.WithPath
432432
}
433433

434-
// Returns the last modification date of the content.
435-
// Deprecated: Use .Lastmod instead.
434+
// Deprecated: Use .Site.Lastmod instead.
436435
func (s *Site) LastChange() time.Time {
436+
hugo.Deprecate(".Site.LastChange", "Use .Site.Lastmod instead.", "v0.123.0")
437437
return s.lastmod
438438
}
439439

@@ -459,13 +459,13 @@ func (s *Site) Social() map[string]string {
459459
return s.conf.Social
460460
}
461461

462-
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
462+
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead.
463463
func (s *Site) DisqusShortname() string {
464464
hugo.Deprecate(".Site.DisqusShortname", "Use .Site.Config.Services.Disqus.Shortname instead.", "v0.120.0")
465465
return s.Config().Services.Disqus.Shortname
466466
}
467467

468-
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead
468+
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead.
469469
func (s *Site) GoogleAnalytics() string {
470470
hugo.Deprecate(".Site.GoogleAnalytics", "Use .Site.Config.Services.GoogleAnalytics.ID instead.", "v0.120.0")
471471
return s.Config().Services.GoogleAnalytics.ID
@@ -484,7 +484,9 @@ func (s *Site) BuildDrafts() bool {
484484
return s.conf.BuildDrafts
485485
}
486486

487+
// Deprecated: Use hugo.IsMultiLingual instead.
487488
func (s *Site) IsMultiLingual() bool {
489+
hugo.Deprecate(".Site.IsMultiLingual", "Use hugo.IsMultiLingual instead.", "v0.124.0")
488490
return s.h.isMultiLingual()
489491
}
490492

resources/page/page_matcher_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ func TestDecodeCascadeConfig(t *testing.T) {
157157
}
158158

159159
type testConfig struct {
160-
environment string
161-
running bool
162-
workingDir string
163-
multihost bool
160+
environment string
161+
running bool
162+
workingDir string
163+
multihost bool
164+
multilingual bool
164165
}
165166

166167
func (c testConfig) Environment() string {
@@ -179,6 +180,10 @@ func (c testConfig) IsMultihost() bool {
179180
return c.multihost
180181
}
181182

183+
func (c testConfig) IsMultiLingual() bool {
184+
return c.multilingual
185+
}
186+
182187
func TestIsGlobWithExtension(t *testing.T) {
183188
c := qt.New(t)
184189

resources/page/site.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ type Site interface {
5454
// A shortcut to the home
5555
Home() Page
5656

57-
// Returns true if we're running in a server.
58-
// Deprecated: use hugo.IsServer instead
57+
// Deprecated: Use hugo.IsServer instead.
5958
IsServer() bool
6059

6160
// Returns the server port.
@@ -64,7 +63,6 @@ type Site interface {
6463
// Returns the configured title for this Site.
6564
Title() string
6665

67-
// Returns the configured language code for this Site.
6866
// Deprecated: Use .Language.LanguageCode instead.
6967
LanguageCode() string
7068

@@ -86,7 +84,6 @@ type Site interface {
8684
// Returns a taxonomy map.
8785
Taxonomies() TaxonomyList
8886

89-
// Returns the last modification date of the content.
9087
// Deprecated: Use .Lastmod instead.
9188
LastChange() time.Time
9289

@@ -129,13 +126,13 @@ type Site interface {
129126
// BuildDrafts is deprecated and will be removed in a future release.
130127
BuildDrafts() bool
131128

132-
// IsMultiLingual reports whether this site is configured with more than one language.
129+
// Deprecated: Use hugo.IsMultiLingual instead.
133130
IsMultiLingual() bool
134131

135132
// LanguagePrefix returns the language prefix for this site.
136133
LanguagePrefix() string
137134

138-
// Deprecated. Use site.Home.OutputFormats.Get "rss" instead.
135+
// Deprecated: Use .Site.Home.OutputFormats.Get "rss" instead.
139136
RSSLink() template.URL
140137
}
141138

@@ -180,7 +177,7 @@ func (s *siteWrapper) Authors() AuthorList {
180177
return AuthorList{}
181178
}
182179

183-
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead
180+
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead.
184181
func (s *siteWrapper) GoogleAnalytics() string {
185182
return s.s.GoogleAnalytics()
186183
}
@@ -217,7 +214,7 @@ func (s *siteWrapper) Home() Page {
217214
return s.s.Home()
218215
}
219216

220-
// Deprecated: use hugo.IsServer instead
217+
// Deprecated: Use hugo.IsServer instead.
221218
func (s *siteWrapper) IsServer() bool {
222219
return s.s.IsServer()
223220
}
@@ -262,9 +259,9 @@ func (s *siteWrapper) Taxonomies() TaxonomyList {
262259
return s.s.Taxonomies()
263260
}
264261

262+
// Deprecated: Use .Site.Lastmod instead.
265263
func (s *siteWrapper) LastChange() time.Time {
266-
hugo.Deprecate(".Site.LastChange", "Use .Site.Lastmod instead.", "v0.123.0")
267-
return s.s.Lastmod()
264+
return s.s.LastChange()
268265
}
269266

270267
func (s *siteWrapper) Lastmod() time.Time {
@@ -295,11 +292,12 @@ func (s *siteWrapper) BuildDrafts() bool {
295292
return s.s.BuildDrafts()
296293
}
297294

295+
// Deprecated: Use hugo.IsMultiLingual instead.
298296
func (s *siteWrapper) IsMultiLingual() bool {
299297
return s.s.IsMultiLingual()
300298
}
301299

302-
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
300+
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead.
303301
func (s *siteWrapper) DisqusShortname() string {
304302
return s.s.DisqusShortname()
305303
}
@@ -308,6 +306,7 @@ func (s *siteWrapper) LanguagePrefix() string {
308306
return s.s.LanguagePrefix()
309307
}
310308

309+
// Deprecated: Use .Site.Home.OutputFormats.Get "rss" instead.
311310
func (s *siteWrapper) RSSLink() template.URL {
312311
return s.s.RSSLink()
313312
}
@@ -342,6 +341,7 @@ func (t testSite) ServerPort() int {
342341
return 1313
343342
}
344343

344+
// Deprecated: Use .Site.Lastmod instead.
345345
func (testSite) LastChange() (t time.Time) {
346346
return
347347
}
@@ -386,7 +386,7 @@ func (t testSite) Languages() langs.Languages {
386386
return nil
387387
}
388388

389-
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead
389+
// Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead.
390390
func (t testSite) GoogleAnalytics() string {
391391
return ""
392392
}
@@ -395,7 +395,7 @@ func (t testSite) MainSections() []string {
395395
return nil
396396
}
397397

398-
// Deprecated: use hugo.IsServer instead
398+
// Deprecated: Use hugo.IsServer instead.
399399
func (t testSite) IsServer() bool {
400400
return false
401401
}
@@ -444,7 +444,7 @@ func (s testSite) Config() SiteConfig {
444444
return SiteConfig{}
445445
}
446446

447-
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
447+
// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead.
448448
func (testSite) DisqusShortname() string {
449449
return ""
450450
}
@@ -453,6 +453,7 @@ func (s testSite) BuildDrafts() bool {
453453
return false
454454
}
455455

456+
// Deprecated: Use hugo.IsMultiLingual instead.
456457
func (s testSite) IsMultiLingual() bool {
457458
return false
458459
}
@@ -461,6 +462,7 @@ func (s testSite) Param(key any) (any, error) {
461462
return nil, nil
462463
}
463464

465+
// Deprecated: Use .Site.Home.OutputFormats.Get "rss" instead.
464466
func (s testSite) RSSLink() template.URL {
465467
return ""
466468
}

source/fileInfo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (fi *File) Extension() string {
6161
func (fi *File) Ext() string { return fi.p().Ext() }
6262

6363
// Lang returns a file's language (e.g. "sv").
64-
// Deprecated: use .Page.Language.Lang instead.
64+
// Deprecated: Use .Page.Language.Lang instead.
6565
func (fi *File) Lang() string {
6666
hugo.Deprecate(".Page.File.Lang", "Use .Page.Language.Lang instead.", "v0.123.0")
6767
return fi.fim.Meta().Lang

testscripts/commands/hugo_is_multihost.txt

-13
This file was deleted.

0 commit comments

Comments
 (0)