@@ -17,6 +17,7 @@ import (
1717 "context"
1818 "fmt"
1919 "io"
20+ "iter"
2021 "path"
2122 "sort"
2223 "strconv"
@@ -367,8 +368,9 @@ func (m *pageMap) getPagesInSection(q pageMapQueryPagesInSection) page.Pages {
367368 }
368369
369370 w := & doctree.NodeShiftTreeWalker [contentNodeI ]{
370- Tree : m .treePages ,
371- Prefix : prefix ,
371+ Tree : m .treePages ,
372+ Prefix : prefix ,
373+ DelegeeFallback : true ,
372374 }
373375
374376 w .Handle = func (key string , n contentNodeI , match doctree.DimensionFlag ) (bool , error ) {
@@ -649,6 +651,7 @@ type contentNodeI interface {
649651 identity.ForEeachIdentityProvider
650652 Path () string
651653 isContentNodeBranch () bool
654+ matchDirectOrInDelegees (doctree.Dimensions ) contentNodeI
652655 buildStateReseter
653656 resource.StaleMarker
654657}
@@ -672,6 +675,10 @@ func (n contentNodeIs) isContentNodeBranch() bool {
672675 return n .one ().isContentNodeBranch ()
673676}
674677
678+ func (p contentNodeIs ) matchDirectOrInDelegees (doctree.Dimensions ) contentNodeI {
679+ panic ("not implemented" )
680+ }
681+
675682func (n contentNodeIs ) GetIdentity () identity.Identity {
676683 return n .one ().GetIdentity ()
677684}
@@ -750,8 +757,18 @@ func (s *contentNodeShifter) Delete(n contentNodeI, dimension doctree.Dimensions
750757 }
751758}
752759
753- func (s * contentNodeShifter ) Shift (n contentNodeI , dims doctree.Dimensions , exact bool ) (contentNodeI , bool , doctree.DimensionFlag ) {
754- // How accurate is the match.
760+ func (s * contentNodeShifter ) findDelegee (q doctree.Dimensions , candidates iter.Seq [contentNodeI ]) contentNodeI {
761+ for n := range candidates {
762+ if nn := n .matchDirectOrInDelegees (q ); nn != nil {
763+ return nn
764+ }
765+ }
766+ return nil
767+ }
768+
769+ func (s * contentNodeShifter ) Shift (n contentNodeI , dims doctree.Dimensions , exact , delegeeFallback bool ) (contentNodeI , bool , doctree.DimensionFlag ) {
770+ // dims: language, version and role
771+ // How accurate is the match. TODO1 revise this.
755772 accuracy := doctree .DimensionLanguage
756773 switch v := n .(type ) {
757774 case contentNodeIs :
@@ -762,6 +779,20 @@ func (s *contentNodeShifter) Shift(n contentNodeI, dims doctree.Dimensions, exac
762779 if vv != nil {
763780 return vv , true , accuracy
764781 }
782+ if ! delegeeFallback {
783+ return nil , false , 0
784+ }
785+ iter := func (yield func (n contentNodeI ) bool ) {
786+ for _ , nn := range v {
787+ if ! yield (nn ) {
788+ return
789+ }
790+ }
791+ }
792+ if vv = s .findDelegee (dims , iter ); vv != nil {
793+ fmt .Println (n .Path (), "found delegee" , dims , vv ) // TODO1
794+ return vv , true , accuracy
795+ }
765796 return nil , false , 0
766797 case resourceSources :
767798 vv := v [dims ]
@@ -1050,7 +1081,7 @@ func (m *pageMap) debugPrint(prefix string, maxLevel int, w io.Writer) {
10501081
10511082 resourceWalker .Handle = func (ss string , n contentNodeI , match doctree.DimensionFlag ) (bool , error ) {
10521083 if isBranch {
1053- ownerKey , _ := pageWalker .Tree .LongestPrefix (ss , true , nil )
1084+ ownerKey , _ := pageWalker .Tree .LongestPrefix (ss , true , false , nil )
10541085 if ownerKey != keyPage {
10551086 // Stop walking downwards, someone else owns this resource.
10561087 pageWalker .SkipPrefix (ownerKey + "/" )
@@ -1500,7 +1531,7 @@ func (sa *sitePagesAssembler) applyAggregates() error {
15001531
15011532 rw .Handle = func (resourceKey string , n contentNodeI , match doctree.DimensionFlag ) (bool , error ) {
15021533 if isBranch {
1503- ownerKey , _ := pw .Tree .LongestPrefix (resourceKey , true , nil )
1534+ ownerKey , _ := pw .Tree .LongestPrefix (resourceKey , true , false , nil )
15041535 if ownerKey != keyPage {
15051536 // Stop walking downwards, someone else owns this resource.
15061537 rw .SkipPrefix (ownerKey + "/" )
0 commit comments