Skip to content

Commit b138f82

Browse files
committed
Work
1 parent 0dba9e2 commit b138f82

25 files changed

+289
-228
lines changed

common/hugo/hugo.go

+46-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/gohugoio/hugo/common/hexec"
3333
"github.com/gohugoio/hugo/common/loggers"
3434
"github.com/gohugoio/hugo/common/maps"
35+
"github.com/gohugoio/hugo/common/version"
3536
"github.com/gohugoio/hugo/hugofs/files"
3637

3738
"github.com/spf13/afero"
@@ -80,7 +81,7 @@ type HugoInfo struct {
8081
}
8182

8283
// Version returns the current version as a comparable version string.
83-
func (i HugoInfo) Version() VersionString {
84+
func (i HugoInfo) Version() version.VersionString {
8485
return CurrentVersion.Version()
8586
}
8687

@@ -451,7 +452,7 @@ func deprecateLevelWithLogger(item, alternative, version string, level logg.Leve
451452
// We want people to run at least the current and previous version without any warnings.
452453
// We want people who don't update Hugo that often to see the warnings and errors before we remove the feature.
453454
func deprecationLogLevelFromVersion(ver string) logg.Level {
454-
from := MustParseVersion(ver)
455+
from := version.MustParseVersion(ver)
455456
to := CurrentVersion
456457
minorDiff := to.Minor - from.Minor
457458
switch {
@@ -465,3 +466,46 @@ func deprecationLogLevelFromVersion(ver string) logg.Level {
465466
return logg.LevelInfo
466467
}
467468
}
469+
470+
// BuildVersionString creates a version string. This is what you see when
471+
// running "hugo version".
472+
func BuildVersionString() string {
473+
// program := "Hugo Static Site Generator"
474+
program := "hugo"
475+
476+
version := "v" + CurrentVersion.String()
477+
478+
bi := getBuildInfo()
479+
if bi == nil {
480+
return version
481+
}
482+
if bi.Revision != "" {
483+
version += "-" + bi.Revision
484+
}
485+
if IsExtended {
486+
version += "+extended"
487+
}
488+
if IsWithdeploy {
489+
version += "+withdeploy"
490+
}
491+
492+
osArch := bi.GoOS + "/" + bi.GoArch
493+
494+
date := bi.RevisionTime
495+
if date == "" {
496+
// Accept vendor-specified build date if .git/ is unavailable.
497+
date = buildDate
498+
}
499+
if date == "" {
500+
date = "unknown"
501+
}
502+
503+
versionString := fmt.Sprintf("%s %s %s BuildDate=%s",
504+
program, version, osArch, date)
505+
506+
if vendorInfo != "" {
507+
versionString += " VendorInfo=" + vendorInfo
508+
}
509+
510+
return versionString
511+
}

common/hugo/hugo_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/bep/logg"
2222
qt "github.com/frankban/quicktest"
23+
"github.com/gohugoio/hugo/common/version"
2324
)
2425

2526
func TestHugoInfo(t *testing.T) {
@@ -29,7 +30,7 @@ func TestHugoInfo(t *testing.T) {
2930
hugoInfo := NewInfo(conf, nil)
3031

3132
c.Assert(hugoInfo.Version(), qt.Equals, CurrentVersion.Version())
32-
c.Assert(fmt.Sprintf("%T", VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
33+
c.Assert(fmt.Sprintf("%T", version.VersionString("")), qt.Equals, fmt.Sprintf("%T", hugoInfo.Version()))
3334
c.Assert(hugoInfo.WorkingDir(), qt.Equals, "/mywork")
3435

3536
bi := getBuildInfo()

common/hugo/version_current.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -13,9 +13,11 @@
1313

1414
package hugo
1515

16+
import "github.com/gohugoio/hugo/common/version"
17+
1618
// CurrentVersion represents the current build version.
1719
// This should be the only one.
18-
var CurrentVersion = Version{
20+
var CurrentVersion = version.Version{
1921
Major: 0,
2022
Minor: 148,
2123
PatchLevel: 0,

common/hugo/version.go renamed to common/version/version.go

+24-72
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package hugo
14+
package version
1515

1616
import (
1717
"fmt"
@@ -55,7 +55,7 @@ func (v Version) Version() VersionString {
5555

5656
// Compare implements the compare.Comparer interface.
5757
func (h Version) Compare(other any) int {
58-
return compareVersions(h, other)
58+
return CompareVersions(h, other)
5959
}
6060

6161
// VersionString represents a Hugo version string.
@@ -67,7 +67,7 @@ func (h VersionString) String() string {
6767

6868
// Compare implements the compare.Comparer interface.
6969
func (h VersionString) Compare(other any) int {
70-
return compareVersions(h.Version(), other)
70+
return CompareVersions(h.Version(), other)
7171
}
7272

7373
func (h VersionString) Version() Version {
@@ -134,98 +134,50 @@ func (v Version) NextPatchLevel(level int) Version {
134134
return prev
135135
}
136136

137-
// BuildVersionString creates a version string. This is what you see when
138-
// running "hugo version".
139-
func BuildVersionString() string {
140-
// program := "Hugo Static Site Generator"
141-
program := "hugo"
142-
143-
version := "v" + CurrentVersion.String()
144-
145-
bi := getBuildInfo()
146-
if bi == nil {
147-
return version
148-
}
149-
if bi.Revision != "" {
150-
version += "-" + bi.Revision
151-
}
152-
if IsExtended {
153-
version += "+extended"
154-
}
155-
if IsWithdeploy {
156-
version += "+withdeploy"
157-
}
158-
159-
osArch := bi.GoOS + "/" + bi.GoArch
160-
161-
date := bi.RevisionTime
162-
if date == "" {
163-
// Accept vendor-specified build date if .git/ is unavailable.
164-
date = buildDate
165-
}
166-
if date == "" {
167-
date = "unknown"
168-
}
169-
170-
versionString := fmt.Sprintf("%s %s %s BuildDate=%s",
171-
program, version, osArch, date)
172-
173-
if vendorInfo != "" {
174-
versionString += " VendorInfo=" + vendorInfo
175-
}
176-
177-
return versionString
178-
}
179-
180137
func version(major, minor, patch int, suffix string) string {
181138
if patch > 0 || minor > 53 {
182139
return fmt.Sprintf("%d.%d.%d%s", major, minor, patch, suffix)
183140
}
184141
return fmt.Sprintf("%d.%d%s", major, minor, suffix)
185142
}
186143

187-
// CompareVersion compares the given version string or number against the
188-
// running Hugo version.
189-
// It returns -1 if the given version is less than, 0 if equal and 1 if greater than
190-
// the running version.
191-
func CompareVersion(version any) int {
192-
return compareVersions(CurrentVersion, version)
193-
}
194-
195-
func compareVersions(inVersion Version, in any) int {
144+
// CompareVersion compares v1 with v2.
145+
// It returns -1 if the v2 is less than, 0 if equal and 1 if greater than
146+
// v1.
147+
func CompareVersions(v1 Version, v2 any) int {
196148
var c int
197-
switch d := in.(type) {
149+
switch d := v2.(type) {
198150
case float64:
199-
c = compareFloatWithVersion(d, inVersion)
151+
c = compareFloatWithVersion(d, v1)
200152
case float32:
201-
c = compareFloatWithVersion(float64(d), inVersion)
153+
c = compareFloatWithVersion(float64(d), v1)
202154
case int:
203-
c = compareFloatWithVersion(float64(d), inVersion)
155+
c = compareFloatWithVersion(float64(d), v1)
204156
case int32:
205-
c = compareFloatWithVersion(float64(d), inVersion)
157+
c = compareFloatWithVersion(float64(d), v1)
206158
case int64:
207-
c = compareFloatWithVersion(float64(d), inVersion)
159+
c = compareFloatWithVersion(float64(d), v1)
208160
case Version:
209-
if d.Major == inVersion.Major && d.Minor == inVersion.Minor && d.PatchLevel == inVersion.PatchLevel {
210-
return strings.Compare(inVersion.Suffix, d.Suffix)
161+
if d.Major == v1.Major && d.Minor == v1.Minor && d.PatchLevel == v1.PatchLevel {
162+
return strings.Compare(v1.Suffix, d.Suffix)
211163
}
212-
if d.Major > inVersion.Major {
164+
if d.Major > v1.Major {
213165
return 1
214-
} else if d.Major < inVersion.Major {
166+
} else if d.Major < v1.Major {
215167
return -1
216168
}
217-
if d.Minor > inVersion.Minor {
169+
if d.Minor > v1.Minor {
218170
return 1
219-
} else if d.Minor < inVersion.Minor {
171+
} else if d.Minor < v1.Minor {
220172
return -1
221173
}
222-
if d.PatchLevel > inVersion.PatchLevel {
174+
if d.PatchLevel > v1.PatchLevel {
223175
return 1
224-
} else if d.PatchLevel < inVersion.PatchLevel {
176+
} else if d.PatchLevel < v1.PatchLevel {
225177
return -1
226178
}
227179
default:
228-
s, err := cast.ToStringE(in)
180+
s, err := cast.ToStringE(v2)
229181
if err != nil {
230182
return -1
231183
}
@@ -234,7 +186,7 @@ func compareVersions(inVersion Version, in any) int {
234186
if err != nil {
235187
return -1
236188
}
237-
return inVersion.Compare(v)
189+
return v1.Compare(v)
238190

239191
}
240192

common/hugo/version_test.go renamed to common/version/version_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015 The Hugo Authors. All rights reserved.
1+
// Copyright 2025 The Hugo Authors. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package hugo
14+
package version
1515

1616
import (
1717
"testing"
@@ -50,25 +50,25 @@ func TestHugoVersion(t *testing.T) {
5050
func TestCompareVersions(t *testing.T) {
5151
c := qt.New(t)
5252

53-
c.Assert(compareVersions(MustParseVersion("0.20.0"), 0.20), qt.Equals, 0)
54-
c.Assert(compareVersions(MustParseVersion("0.20.0"), float32(0.20)), qt.Equals, 0)
55-
c.Assert(compareVersions(MustParseVersion("0.20.0"), float64(0.20)), qt.Equals, 0)
56-
c.Assert(compareVersions(MustParseVersion("0.19.1"), 0.20), qt.Equals, 1)
57-
c.Assert(compareVersions(MustParseVersion("0.19.3"), "0.20.2"), qt.Equals, 1)
58-
c.Assert(compareVersions(MustParseVersion("0.1"), 3), qt.Equals, 1)
59-
c.Assert(compareVersions(MustParseVersion("0.1"), int32(3)), qt.Equals, 1)
60-
c.Assert(compareVersions(MustParseVersion("0.1"), int64(3)), qt.Equals, 1)
61-
c.Assert(compareVersions(MustParseVersion("0.20"), "0.20"), qt.Equals, 0)
62-
c.Assert(compareVersions(MustParseVersion("0.20.1"), "0.20.1"), qt.Equals, 0)
63-
c.Assert(compareVersions(MustParseVersion("0.20.1"), "0.20"), qt.Equals, -1)
64-
c.Assert(compareVersions(MustParseVersion("0.20.0"), "0.20.1"), qt.Equals, 1)
65-
c.Assert(compareVersions(MustParseVersion("0.20.1"), "0.20.2"), qt.Equals, 1)
66-
c.Assert(compareVersions(MustParseVersion("0.21.1"), "0.22.1"), qt.Equals, 1)
67-
c.Assert(compareVersions(MustParseVersion("0.22.0"), "0.22-DEV"), qt.Equals, -1)
68-
c.Assert(compareVersions(MustParseVersion("0.22.0"), "0.22.1-DEV"), qt.Equals, 1)
69-
c.Assert(compareVersions(MustParseVersion("0.22.0-DEV"), "0.22"), qt.Equals, 1)
70-
c.Assert(compareVersions(MustParseVersion("0.22.1-DEV"), "0.22"), qt.Equals, -1)
71-
c.Assert(compareVersions(MustParseVersion("0.22.1-DEV"), "0.22.1-DEV"), qt.Equals, 0)
53+
c.Assert(CompareVersions(MustParseVersion("0.20.0"), 0.20), qt.Equals, 0)
54+
c.Assert(CompareVersions(MustParseVersion("0.20.0"), float32(0.20)), qt.Equals, 0)
55+
c.Assert(CompareVersions(MustParseVersion("0.20.0"), float64(0.20)), qt.Equals, 0)
56+
c.Assert(CompareVersions(MustParseVersion("0.19.1"), 0.20), qt.Equals, 1)
57+
c.Assert(CompareVersions(MustParseVersion("0.19.3"), "0.20.2"), qt.Equals, 1)
58+
c.Assert(CompareVersions(MustParseVersion("0.1"), 3), qt.Equals, 1)
59+
c.Assert(CompareVersions(MustParseVersion("0.1"), int32(3)), qt.Equals, 1)
60+
c.Assert(CompareVersions(MustParseVersion("0.1"), int64(3)), qt.Equals, 1)
61+
c.Assert(CompareVersions(MustParseVersion("0.20"), "0.20"), qt.Equals, 0)
62+
c.Assert(CompareVersions(MustParseVersion("0.20.1"), "0.20.1"), qt.Equals, 0)
63+
c.Assert(CompareVersions(MustParseVersion("0.20.1"), "0.20"), qt.Equals, -1)
64+
c.Assert(CompareVersions(MustParseVersion("0.20.0"), "0.20.1"), qt.Equals, 1)
65+
c.Assert(CompareVersions(MustParseVersion("0.20.1"), "0.20.2"), qt.Equals, 1)
66+
c.Assert(CompareVersions(MustParseVersion("0.21.1"), "0.22.1"), qt.Equals, 1)
67+
c.Assert(CompareVersions(MustParseVersion("0.22.0"), "0.22-DEV"), qt.Equals, -1)
68+
c.Assert(CompareVersions(MustParseVersion("0.22.0"), "0.22.1-DEV"), qt.Equals, 1)
69+
c.Assert(CompareVersions(MustParseVersion("0.22.0-DEV"), "0.22"), qt.Equals, 1)
70+
c.Assert(CompareVersions(MustParseVersion("0.22.1-DEV"), "0.22"), qt.Equals, -1)
71+
c.Assert(CompareVersions(MustParseVersion("0.22.1-DEV"), "0.22.1-DEV"), qt.Equals, 0)
7272
}
7373

7474
func TestParseHugoVersion(t *testing.T) {

config/allconfig/allconfig.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ type Config struct {
143143
OutputFormats *config.ConfigNamespace[map[string]output.OutputFormatConfig, output.Formats] `mapstructure:"-"`
144144

145145
// The roles configuration section contains the top level roles configuration options.
146-
Roles *config.ConfigNamespace[map[string]roles.RoleConfig, roles.Roles] `mapstructure:"-"`
146+
Roles *config.ConfigNamespace[map[string]roles.RoleConfig, roles.RolesInternal] `mapstructure:"-"`
147147

148148
// The versions configuration section contains the top level versions configuration options.
149-
Versions *config.ConfigNamespace[map[string]versions.VersionConfig, versions.Versions] `mapstructure:"-"`
149+
Versions *config.ConfigNamespace[map[string]versions.VersionConfig, versions.VersionsInternal] `mapstructure:"-"`
150150

151151
// The outputs configuration section maps a Page Kind (a string) to a slice of output formats.
152152
// This can be overridden in the front matter.

create/content.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"github.com/gohugoio/hugo/hugofs/glob"
2727

2828
"github.com/gohugoio/hugo/common/hexec"
29-
"github.com/gohugoio/hugo/common/hstrings"
3029
"github.com/gohugoio/hugo/common/paths"
30+
"github.com/gohugoio/hugo/common/types"
3131

3232
"github.com/gohugoio/hugo/hugofs"
3333

@@ -291,7 +291,7 @@ func (b *contentBuilder) applyArcheType(contentFilename string, archetypeFi hugo
291291
func (b *contentBuilder) mapArcheTypeDir() error {
292292
var m archetypeMap
293293

294-
seen := map[hstrings.Strings2]bool{}
294+
seen := map[types.Strings2]bool{}
295295

296296
walkFn := func(path string, fim hugofs.FileMetaInfo) error {
297297
if fim.IsDir() {
@@ -301,7 +301,7 @@ func (b *contentBuilder) mapArcheTypeDir() error {
301301
pi := fim.Meta().PathInfo
302302

303303
if pi.IsContent() {
304-
pathLang := hstrings.Strings2{pi.PathBeforeLangAndOutputFormatAndExt(), fim.Meta().Lang}
304+
pathLang := types.Strings2{pi.PathBeforeLangAndOutputFormatAndExt(), fim.Meta().Lang}
305305
if seen[pathLang] {
306306
// Duplicate content file, e.g. page.md and page.html.
307307
// In the regular build, we will filter out the duplicates, but

hugolib/content_map.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (m *pageMap) addPagesFromGoTmplFi(fi hugofs.FileMetaInfo, buildConfig *Buil
362362
Watching: s.Conf.Watching(),
363363
HandlePage: func(pt *pagesfromdata.PagesFromTemplate, pc *pagemeta.PageConfig) error {
364364
s := pt.Site.(*Site)
365-
if err := pc.Compile(pt.GoTmplFi.Meta().PathInfo.Base(), true, "", s.Log, s.Conf); err != nil {
365+
if err := pc.Compile(pt.GoTmplFi.Meta().PathInfo.Base(), true, "", s.Log, s.conf.MediaTypes.Config); err != nil {
366366
return err
367367
}
368368

0 commit comments

Comments
 (0)