Skip to content

Commit c89ca86

Browse files
committed
Add roles and versions as new dimensions (in addition to language)
Fixes #519 Fixes #13680 Fixes #13663 Fixes #13776 Fixes #13855 Fixes #13648 Fixes #13996 Fixes #14001 Fixes #14031
1 parent 8a57d0f commit c89ca86

File tree

207 files changed

+13375
-5481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+13375
-5481
lines changed

‎bench.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gobench --bench BenchmarkSitesMatrixContent/n100/mdtrue --package ./hugolib/sitesmatrix

‎cache/dynacache/dynacache.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func GetOrCreatePartition[K comparable, V any](c *Cache, name string, opts Optio
340340
panic("invalid Weight, must be between 1 and 100")
341341
}
342342

343-
if partitionNameRe.FindString(name) != name {
343+
if !partitionNameRe.MatchString(name) {
344344
panic(fmt.Sprintf("invalid partition name %q", name))
345345
}
346346

‎cache/filecache/filecache_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func newPathsSpec(t *testing.T, fs afero.Fs, configStr string) *helpers.PathSpec
270270
cfg, err := config.FromConfigString(configStr, "toml")
271271
c.Assert(err, qt.IsNil)
272272
acfg := testconfig.GetTestConfig(fs, cfg)
273-
p, err := helpers.NewPathSpec(hugofs.NewFrom(fs, acfg.BaseConfig()), acfg, nil)
273+
p, err := helpers.NewPathSpec(hugofs.NewFrom(fs, acfg.BaseConfig()), acfg, nil, nil)
274274
c.Assert(err, qt.IsNil)
275275
return p
276276
}

‎cache/httpcache/httpcache.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,30 +173,30 @@ func (gm *GlobMatcher) CompilePredicate() (func(string) bool, error) {
173173
if gm.IsZero() {
174174
panic("no includes or excludes")
175175
}
176-
var p predicate.P[string]
176+
var b predicate.PR[string]
177177
for _, include := range gm.Includes {
178178
g, err := glob.Compile(include, '/')
179179
if err != nil {
180180
return nil, err
181181
}
182-
fn := func(s string) bool {
183-
return g.Match(s)
182+
fn := func(s string) predicate.Match {
183+
return predicate.BoolMatch(g.Match(s))
184184
}
185-
p = p.Or(fn)
185+
b = b.Or(fn)
186186
}
187187

188188
for _, exclude := range gm.Excludes {
189189
g, err := glob.Compile(exclude, '/')
190190
if err != nil {
191191
return nil, err
192192
}
193-
fn := func(s string) bool {
194-
return !g.Match(s)
193+
fn := func(s string) predicate.Match {
194+
return predicate.BoolMatch(!g.Match(s))
195195
}
196-
p = p.And(fn)
196+
b = b.And(fn)
197197
}
198198

199-
return p, nil
199+
return b.BoolFunc(), nil
200200
}
201201

202202
func DecodeConfig(_ config.BaseConfig, m map[string]any) (Config, error) {

‎commands/config.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
7171
return fmt.Errorf("language %q not found", c.lang)
7272
}
7373
} else {
74-
config = conf.configs.LanguageConfigSlice[0]
74+
config = conf.configs.LanguageConfigMap[conf.configs.Base.DefaultContentLanguage]
7575
}
7676

7777
var buf bytes.Buffer

‎commands/hugobuilder.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/bep/simplecobra"
3232
"github.com/fsnotify/fsnotify"
3333
"github.com/gohugoio/hugo/common/herrors"
34+
"github.com/gohugoio/hugo/common/hstrings"
3435
"github.com/gohugoio/hugo/common/htime"
3536
"github.com/gohugoio/hugo/common/hugo"
3637
"github.com/gohugoio/hugo/common/loggers"
@@ -143,7 +144,7 @@ func (c *hugoBuilder) getDirList() ([]string, error) {
143144
return nil, err
144145
}
145146

146-
return helpers.UniqueStringsSorted(h.PathSpec.BaseFs.WatchFilenames()), nil
147+
return hstrings.UniqueStringsSorted(h.PathSpec.BaseFs.WatchFilenames()), nil
147148
}
148149

149150
func (c *hugoBuilder) initCPUProfile() (func(), error) {
@@ -827,7 +828,7 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
827828
continue
828829
}
829830

830-
walkAdder := func(path string, f hugofs.FileMetaInfo) error {
831+
walkAdder := func(ctx context.Context, path string, f hugofs.FileMetaInfo) error {
831832
if f.IsDir() {
832833
c.r.logger.Println("adding created directory to watchlist", path)
833834
if err := watcher.Add(path); err != nil {

‎commands/import.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (c *importCommand) importFromJekyll(args []string) error {
427427
c.r.Println("Importing...")
428428

429429
fileCount := 0
430-
callback := func(path string, fi hugofs.FileMetaInfo) error {
430+
callback := func(ctx context.Context, path string, fi hugofs.FileMetaInfo) error {
431431
if fi.IsDir() {
432432
return nil
433433
}

‎commands/server.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"github.com/fsnotify/fsnotify"
5050
"github.com/gohugoio/hugo/common/herrors"
5151
"github.com/gohugoio/hugo/common/hugo"
52+
"github.com/gohugoio/hugo/langs"
5253
"github.com/gohugoio/hugo/tpl/tplimpl"
5354

5455
"github.com/gohugoio/hugo/common/types"
@@ -627,7 +628,7 @@ func (c *serverCommand) setServerInfoInConfig() error {
627628
panic("no server ports set")
628629
}
629630
return c.withConfE(func(conf *commonConfig) error {
630-
for i, language := range conf.configs.LanguagesDefaultFirst {
631+
for i, language := range conf.configs.Languages {
631632
isMultihost := conf.configs.IsMultihost
632633
var serverPort int
633634
if isMultihost {
@@ -879,7 +880,7 @@ func (c *serverCommand) serve() error {
879880
if isMultihost {
880881
for _, l := range conf.configs.ConfigLangs() {
881882
baseURLs = append(baseURLs, l.BaseURL())
882-
roots = append(roots, l.Language().Lang)
883+
roots = append(roots, l.Language().(*langs.Language).Lang)
883884
}
884885
} else {
885886
l := conf.configs.GetFirstLanguageConfig()

‎common/hashing/hashing.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/cespare/xxhash/v2"
2525
"github.com/gohugoio/hashstructure"
26+
"github.com/gohugoio/hugo/common/hugio"
2627
"github.com/gohugoio/hugo/identity"
2728
)
2829

@@ -38,6 +39,34 @@ func XXHashFromReader(r io.Reader) (uint64, int64, error) {
3839
return h.Sum64(), size, nil
3940
}
4041

42+
type Hasher interface {
43+
io.StringWriter
44+
io.Writer
45+
io.ReaderFrom
46+
Sum64() uint64
47+
}
48+
49+
type HashCloser interface {
50+
Hasher
51+
io.Closer
52+
}
53+
54+
// XxHasher returns a Hasher that uses xxHash.
55+
// Remember to call Close when done.
56+
func XxHasher() HashCloser {
57+
h := getXxHashReadFrom()
58+
return struct {
59+
Hasher
60+
io.Closer
61+
}{
62+
Hasher: h,
63+
Closer: hugio.CloserFunc(func() error {
64+
putXxHashReadFrom(h)
65+
return nil
66+
}),
67+
}
68+
}
69+
4170
// XxHashFromReaderHexEncoded calculates the xxHash for the given reader
4271
// and returns the hash as a hex encoded string.
4372
func XxHashFromReaderHexEncoded(r io.Reader) (string, error) {

‎common/hdebug/debug.go‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2025 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 hdebug
15+
16+
import (
17+
"fmt"
18+
"strings"
19+
"time"
20+
21+
"github.com/gohugoio/hugo/common/types"
22+
"github.com/gohugoio/hugo/htesting"
23+
)
24+
25+
// Printf is a debug print function that should be removed before committing code to the repository.
26+
func Printf(format string, args ...any) {
27+
panicIfRealCI()
28+
if len(args) == 1 && !strings.Contains(format, "%") {
29+
format = format + ": %v"
30+
}
31+
if !strings.HasSuffix(format, "\n") {
32+
format = format + "\n"
33+
}
34+
fmt.Printf(format, args...)
35+
time.Sleep(10 * time.Millisecond) // Give the output a chance to be printed before the program exits.
36+
}
37+
38+
func AssertNotNil(a ...any) {
39+
panicIfRealCI()
40+
for _, v := range a {
41+
if types.IsNil(v) {
42+
panic("hdebug.AssertNotNil: value is nil")
43+
}
44+
}
45+
}
46+
47+
func Panicf(format string, args ...any) {
48+
panicIfRealCI()
49+
// fmt.Println(stack())
50+
if len(args) == 1 && !strings.Contains(format, "%") {
51+
format = format + ": %v"
52+
}
53+
if !strings.HasSuffix(format, "\n") {
54+
format = format + "\n"
55+
}
56+
panic(fmt.Sprintf(format, args...))
57+
}
58+
59+
func panicIfRealCI() {
60+
if htesting.IsRealCI() {
61+
panic("This debug statement should be removed before committing code!")
62+
}
63+
}

0 commit comments

Comments
 (0)