Skip to content

Commit 35d3765

Browse files
committed
Matrix more
1 parent b254b31 commit 35d3765

File tree

7 files changed

+41
-22
lines changed

7 files changed

+41
-22
lines changed

‎hugolib/content_map_page.go‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ var (
666666
type contentNodeIs2 []contentNodeI
667667

668668
func (n contentNodeIs2) Dims() sitematrix.VectorProvider {
669-
panic("contentNodeIs2.Dims: not supported")
669+
panic("Dims(): not supported")
670670
}
671671

672672
func (n contentNodeIs2) Path() string {
@@ -793,9 +793,7 @@ func (s *contentNodeShifter) Delete(n contentNodeI, dims sitematrix.Vector) (con
793793
}
794794
return deleted, wasDeleted, isEmpty
795795
case contentNodeIs2:
796-
if len(v) == 0 {
797-
panic("empty contentNodeIs2")
798-
}
796+
// panic("TODO1 Delete")
799797
// TODO1 implement me.
800798
return nil, false, false
801799

@@ -870,8 +868,6 @@ func absint(i int) int {
870868
}
871869

872870
func (s *contentNodeShifter) Shift(n contentNodeI, dims sitematrix.Vector, exact, delegeeFallback bool) (contentNodeI, bool, sitematrix.Dimension) {
873-
// dims: language, version and role
874-
// How accurate is the match. TODO1 revise this.
875871
accuracy := sitematrix.Language
876872
switch v := n.(type) {
877873
case contentNodeIs:
@@ -897,14 +893,12 @@ func (s *contentNodeShifter) Shift(n contentNodeI, dims sitematrix.Vector, exact
897893
}
898894
return nil, false, 0
899895
case contentNodeIs2:
900-
if len(v) == 0 {
901-
panic("empty contentNodeIs2")
902-
}
903896
for _, vv := range v {
904897
if vv.Dims().HasVector(dims) {
905898
return vv, true, sitematrix.Language
906899
}
907900
}
901+
908902
if !delegeeFallback {
909903
return nil, false, 0
910904
}
@@ -984,6 +978,15 @@ func (s *contentNodeShifter) ForEeachInDimension(n contentNodeI, dims sitematrix
984978
}
985979
}
986980
}
981+
982+
case contentNodeIs2:
983+
for _, v := range vv {
984+
if v.Dims().HasVector(dims) {
985+
if f(v) {
986+
return
987+
}
988+
}
989+
}
987990
default:
988991
if n == nil {
989992
return
@@ -1094,7 +1097,8 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) (contentNodeI, conten
10941097
}*/
10951098

10961099
rs := append(vv, newp)
1097-
return contentNodeIs2(rs), vv.first(), false
1100+
1101+
return rs, vv, false
10981102

10991103
case *resourceSource:
11001104
newp, ok := new.(*resourceSource)

‎hugolib/doctree/nodeshifttree.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,15 @@ func (r *NodeShiftTree[T]) shift(t T, exact, delegeeFallback bool) (T, bool, sit
433433
func (r *NodeShiftTree[T]) get(s string) (T, bool) {
434434
s = cleanKey(s)
435435
v, ok := r.tree.Get(s)
436+
// dims: language, version and role
437+
// How accurate is the match. TODO1 revise this.
438+
436439
if !ok {
437440
var t T
438441
return t, false
439442
}
440443
t, ok, _ := r.shift(v.(T), true, false) // TODO1
444+
441445
return t, ok
442446
}
443447

‎hugolib/page__meta.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ params:
454454
pcfg := pm.pageConfig
455455
params := pcfg.Params
456456
if params == nil {
457-
panic("params not set for " + p.Title())
457+
panic("params not set for " + p.Path())
458458
}
459459

460460
var draft, published, isCJKLanguage *bool

‎hugolib/page__new.go‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (h *HugoSites) newPages(m *pageMeta) (iter.Seq2[int, *pageState], *paths.Pa
4747
// No page created, so nothing to yield.
4848
return
4949
}
50+
5051
if !yield(0, p) {
5152
return
5253
}
@@ -59,6 +60,7 @@ func (h *HugoSites) newPages(m *pageMeta) (iter.Seq2[int, *pageState], *paths.Pa
5960
if !yield(i, p) {
6061
return
6162
}
63+
6264
}
6365
}
6466

@@ -101,15 +103,7 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, []*Site, er
101103
}
102104

103105
pcfg := m.pageConfig
104-
if m.f != nil && m.f.Path() == "_index.md" {
105-
// TODO1: Remove.
106-
107-
fmt.Println("===>", m.f.Path(), pcfg.Languages, pcfg.Versions, pcfg.Roles, "dims", pcfg.Dimensions, "file vectors:", dimensionsFromFile)
108-
pcfg.Dimensions.ForEeachVector(func(v sitematrix.Vector) bool {
109-
fmt.Println("pcfg.Dimensions.Vector", h.Conf.ConfiguredDimensions().ResolveNames(v))
110-
return true
111-
})
112-
}
106+
113107
if pcfg.Lang != "" {
114108
// TODO1
115109
if h.Conf.IsLangDisabled(pcfg.Lang) {

‎hugolib/roles/roles_integration_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ site.GetPage p1: {{ with .Site.GetPage "p1" }}{{ .Title }}|{{ end }}$
263263
// b.AssertFileContent("public/en/index.html", "Title English", "Text English")
264264
b.AssertFileContent("public/v2.0.0/nn/p1/index.html", "Tittel Nynorsk", "Tekst Nynorsk", "site.GetPage p1: Tittel Nynorsk|")
265265
b.AssertFileContent("public/v2.0.0/nn/p2/index.html", "p2 all||", "site.GetPage p2: p2 all", "site.GetPage p1: Tittel Nynorsk|")
266-
b.AssertFileContent("public/v2.0.0/en/p2/index.html", "p2 all||", "sdf")
266+
b.AssertFileContent("public/v2.0.0/en/p2/index.html", "p2 all||", "site.GetPage p1: $")
267+
b.AssertFileContent("public/v2.0.0/nn/p2/index.html", "p2 all||", "site.GetPage p1: Tittel Nynorsk|$")
267268
b.AssertFileContent("public/v1.2.3/en/p2/index.html", "p2 all||", "site.GetPage p2: p2 all")
268269
}
269270

‎hugolib/sitematrix/sets.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ func (s *IntSets) EqualsVector(other VectorProvider) bool {
107107
})
108108
}
109109

110+
// ApplyDefaultsIfNotSet applies default values to the IntSets if they are not already set.
111+
func (s *IntSets) SetDefaultsIfNotSet(cfg ConfiguredDimensions) {
112+
if s.Languages == nil {
113+
s.Languages = maps.NewOrderedIntSet()
114+
s.Languages.Set(cfg.ConfiguredLanguages.IndexDefault())
115+
}
116+
if s.Versions == nil {
117+
s.Versions = maps.NewOrderedIntSet()
118+
s.Versions.Set(cfg.ConfiguredVersions.IndexDefault())
119+
}
120+
if s.Roles == nil {
121+
s.Roles = maps.NewOrderedIntSet()
122+
s.Roles.Set(cfg.ConfiguredRoles.IndexDefault())
123+
}
124+
}
125+
110126
func (s *IntSets) SetFrom(other *IntSets) {
111127
if other == nil {
112128
return

‎resources/page/pagemeta/page_frontmatter.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ func (p *PageConfig) CompileEearly(conf config.AllProvider, dimensionsFromFile *
329329
p.Languages = hstrings.UniqueStringsReuse(p.Languages)
330330
}
331331

332-
// TODO1 default when?
333332
sets, err := sitematrix.NewIntSets2(conf.ConfiguredDimensions(), false, p.Languages, p.Versions, p.Roles)
334333
if err != nil {
335334
return fmt.Errorf("failed to create dimensions sets: %w", err)
336335
}
337336
sets.SetFrom(dimensionsFromFile)
337+
sets.SetDefaultsIfNotSet(conf.ConfiguredDimensions())
338338
p.Dimensions = sets
339339

340340
setsDelegees, err := sitematrix.NewIntSets2(conf.ConfiguredDimensions(), false, p.LanguageDelegees, p.VersionDelegees, p.RoleDelegees)

0 commit comments

Comments
 (0)