return err
}
defer f.Close()
- yamlEnc := yaml.NewEncoder(f, yaml.AutoInt())
+ yamlEnc := yaml.NewEncoder(f, yaml.UseSingleQuote(true), yaml.AutoInt())
if err := yamlEnc.Encode(m); err != nil {
return err
}
if defaultContentRole, err = roles.init(defaultContentRole); err != nil {
return roles, nil, err
}
- return roles, nil, nil
+ return roles, roles.roleConfigs, nil
})
return v, defaultContentRole, err
package sitesmatrix_test
import (
+ "encoding/json"
"fmt"
"strings"
"testing"
return b
}
+// See #14132. We recently reworked the config structs for languages, versions, and roles,
+// which made them incomplete when generating the docshelper YAML file.
+// Add a test here to ensure we don't regress.
+func TestUnmarshalSitesMatrixConfig(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+defaultContentLanguage = "en"
+defaultContentLanguageInSubDir = true
+defaultCOntentVersionInSubDir = true
+defaultContentVersion = "v1.0.0"
+defaultContentRole = "guest"
+defaultContentRoleInSubDir = true
+
+[moule.mounts]
+source = 'content'
+target = 'content'
+
+
+[languages]
+[languages.en]
+
+[versions]
+[versions."v1.0.0"]
+
+[roles]
+[roles.guest]
+
+`
+
+ b := hugolib.Test(t, files)
+
+ toJSONAndMap := func(v any) map[string]any {
+ bb, err := json.Marshal(v)
+ b.Assert(err, qt.IsNil)
+ var m map[string]any
+ err = json.Unmarshal(bb, &m)
+ b.Assert(err, qt.IsNil)
+ return m
+ }
+
+ conf := b.H.Configs.Base
+
+ b.Assert(toJSONAndMap(conf.Languages), qt.DeepEquals,
+ map[string]any{
+ "en": map[string]any{
+ "Disabled": bool(false),
+ "LanguageCode": "",
+ "LanguageDirection": "",
+ "LanguageName": "",
+ "Title": "",
+ "Weight": float64(0),
+ },
+ })
+
+ b.Assert(toJSONAndMap(conf.Versions), qt.DeepEquals, map[string]any{
+ "v1.0.0": map[string]any{
+ "Weight": float64(0),
+ },
+ })
+
+ b.Assert(toJSONAndMap(conf.Roles), qt.DeepEquals, map[string]any{
+ "guest": map[string]any{
+ "Weight": float64(0),
+ },
+ })
+
+ firstMount := conf.Module.Mounts[0]
+ b.Assert(toJSONAndMap(firstMount.Sites.Matrix), qt.DeepEquals, map[string]any{
+ "languages": nil,
+ "versions": nil,
+ "roles": nil,
+ })
+ b.Assert(toJSONAndMap(firstMount.Sites.Complements), qt.DeepEquals, map[string]any{
+ "languages": nil,
+ "versions": nil,
+ "roles": nil,
+ })
+}
+
func TestSitesMatrixContentBenchmark(t *testing.T) {
const numPages = 3
b := newSitesMatrixContentBenchmarkBuilder(t, numPages, false, true)
// Sites holds configuration about which sites a file/content/page/resource belongs to.
type Sites struct {
// Matrix defines what sites to build this content for.
- Matrix StringSlices `mapstructure:"matrix" json:"matrix,omitzero"`
+ Matrix StringSlices `mapstructure:"matrix" json:"matrix"`
// Complements defines what sites to complement with this content.
- Complements StringSlices `mapstructure:"complements" json:"complements,omitzero"`
+ Complements StringSlices `mapstructure:"complements" json:"complements"`
}
func (s *Sites) Equal(other Sites) bool {
if err := versions.init(defaultContentVersion); err != nil {
return versions, nil, err
}
- return versions, nil, nil
+ return versions, versions.versionConfigs, nil
})
}
if defaultContentLanguage, err = languages.init(defaultContentLanguage, disabledLanguages); err != nil {
return languages, nil, err
}
- return languages, nil, nil
+ return languages, languages.LanguageConfigs, nil
})
return v, defaultContentLanguage, err
Target string
// Any file in this mount will be associated with this language.
- Lang string
+ // Deprecated, use Sites instead.
+ Lang string `json:"-"`
// Sites defines which sites this mount applies to.
Sites sitesmatrix.Sites
// Include only files matching the given Glob patterns (string or slice).
// Deprecated, use Files instead.
- IncludeFiles any
+ IncludeFiles any `json:"-"`
// Exclude all files matching the given Glob patterns (string or slice).
// Deprecated, use Files instead.
- ExcludeFiles any
+ ExcludeFiles any `json:"-"`
// Disable watching in watch mode for this mount.
DisableWatch bool