diff --git a/internal/domain/contenthub/entity/pagetrees.go b/internal/domain/contenthub/entity/pagetrees.go index fea6416..09dde5e 100644 --- a/internal/domain/contenthub/entity/pagetrees.go +++ b/internal/domain/contenthub/entity/pagetrees.go @@ -40,6 +40,19 @@ func (t *PageTrees) CreateMutableTrees() { } } +type weightPage struct { + *ordinalWeightPage + page contenthub.Page +} + +func (n *weightPage) Page() contenthub.Page { + return n.page +} + +func (n *weightPage) Owner() contenthub.Page { + return n.ordinalWeightPage.Page +} + type ordinalWeightPage struct { ordinal int weight int diff --git a/internal/domain/contenthub/entity/pagesourceshifter.go b/internal/domain/contenthub/entity/shifter.go similarity index 54% rename from internal/domain/contenthub/entity/pagesourceshifter.go rename to internal/domain/contenthub/entity/shifter.go index 2ac3da9..d83a930 100644 --- a/internal/domain/contenthub/entity/pagesourceshifter.go +++ b/internal/domain/contenthub/entity/shifter.go @@ -4,14 +4,14 @@ import ( "github.com/gohugonet/hugoverse/pkg/doctree" ) -type SourceShifter struct{} +type Shifter struct{} -func (s *SourceShifter) Delete(n *PageTreesNode, dimension doctree.Dimension) (bool, bool) { +func (s *Shifter) Delete(n *PageTreesNode, dimension doctree.Dimension) (bool, bool) { wasDeleted := n.delete(dimension[doctree.DimensionLanguage.Index()]) return wasDeleted, n.isEmpty() } -func (s *SourceShifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exact bool) (*PageTreesNode, bool, doctree.DimensionFlag) { +func (s *Shifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exact bool) (*PageTreesNode, bool, doctree.DimensionFlag) { newNode, found := n.shift(dimension[doctree.DimensionLanguage.Index()], exact) if newNode != nil { if found { @@ -23,17 +23,17 @@ func (s *SourceShifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exa return nil, false, doctree.DimensionNone } -func (s *SourceShifter) ForEachInDimension(n *PageTreesNode, d int, f func(*PageTreesNode) bool) { +func (s *Shifter) ForEachInDimension(n *PageTreesNode, d int, f func(*PageTreesNode) bool) { if d != doctree.DimensionLanguage.Index() { panic("only language dimension supported") } f(n) } -func (s *SourceShifter) InsertInto(old, new *PageTreesNode, dimension doctree.Dimension) *PageTreesNode { +func (s *Shifter) InsertInto(old, new *PageTreesNode, dimension doctree.Dimension) *PageTreesNode { return old.mergeWithLang(new, dimension[doctree.DimensionLanguage.Index()]) } -func (s *SourceShifter) Insert(old, new *PageTreesNode) *PageTreesNode { +func (s *Shifter) Insert(old, new *PageTreesNode) *PageTreesNode { return old.merge(new) } diff --git a/internal/domain/contenthub/entity/shifterpage.go b/internal/domain/contenthub/entity/shifterpage.go new file mode 100644 index 0000000..da94746 --- /dev/null +++ b/internal/domain/contenthub/entity/shifterpage.go @@ -0,0 +1,20 @@ +package entity + +import ( + "github.com/gohugonet/hugoverse/pkg/doctree" +) + +type PageShifter struct { + *Shifter +} + +func (s *PageShifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exact bool) (*PageTreesNode, bool, doctree.DimensionFlag) { + newNode, found := n.shift(dimension[doctree.DimensionLanguage.Index()], exact) + if newNode != nil { + if found { + return newNode, true, doctree.DimensionLanguage + } + } + + return nil, false, doctree.DimensionNone +} diff --git a/internal/domain/contenthub/entity/shifterpagesource.go b/internal/domain/contenthub/entity/shifterpagesource.go new file mode 100644 index 0000000..064acfa --- /dev/null +++ b/internal/domain/contenthub/entity/shifterpagesource.go @@ -0,0 +1,21 @@ +package entity + +import ( + "github.com/gohugonet/hugoverse/pkg/doctree" +) + +type SourceShifter struct { + *Shifter +} + +func (s *SourceShifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exact bool) (*PageTreesNode, bool, doctree.DimensionFlag) { + newNode, found := n.shift(dimension[doctree.DimensionLanguage.Index()], exact) + if newNode != nil { + if found { + return newNode, true, doctree.DimensionLanguage + } + return newNode, true, doctree.DimensionNone + } + + return nil, false, doctree.DimensionNone +} diff --git a/internal/domain/contenthub/entity/walk.go b/internal/domain/contenthub/entity/walk.go index d74111d..350ad12 100644 --- a/internal/domain/contenthub/entity/walk.go +++ b/internal/domain/contenthub/entity/walk.go @@ -66,8 +66,16 @@ func (ch *ContentHub) WalkTaxonomies(langIndex int, walker contenthub.WalkTaxono doctree.LockTypeRead, paths.AddTrailingSlash(s), func(ss string, wn *WeightedTermTreeNode) (bool, error) { + sp, found := wn.getPage() + if !found { + return false, nil + } - if err := walker(viewName.Plural(), k, wn.term); err != nil { + if err := walker(viewName.Plural(), k, + &weightPage{ + ordinalWeightPage: wn.term, + page: sp}, + ); err != nil { return false, err } diff --git a/internal/domain/contenthub/factory/hub.go b/internal/domain/contenthub/factory/hub.go index a79d8fb..d613f87 100644 --- a/internal/domain/contenthub/factory/hub.go +++ b/internal/domain/contenthub/factory/hub.go @@ -157,16 +157,16 @@ func newContentSpec() (*entity.ContentSpec, error) { } func newPageTree() *entity.PageTrees { - treeConfig := doctree.Config[*entity.PageTreesNode]{ - Shifter: &entity.SourceShifter{}, - } - pageTrees := &entity.PageTrees{ TreePages: doctree.New( - treeConfig, + doctree.Config[*entity.PageTreesNode]{ + Shifter: &entity.PageShifter{Shifter: &entity.Shifter{}}, + }, ), TreeResources: doctree.New( - treeConfig, + doctree.Config[*entity.PageTreesNode]{ + Shifter: &entity.SourceShifter{Shifter: &entity.Shifter{}}, + }, ), TreeTaxonomyEntries: doctree.NewTreeShiftTree[*entity.WeightedTermTreeNode]( doctree.DimensionLanguage.Index(), 2), // TODO: get this from config diff --git a/internal/domain/contenthub/type.go b/internal/domain/contenthub/type.go index 39442d1..851e3c3 100644 --- a/internal/domain/contenthub/type.go +++ b/internal/domain/contenthub/type.go @@ -279,8 +279,8 @@ type Page interface { type OrdinalWeightPage interface { Weight() int Ordinal() int - - Page + Page() Page + Owner() Page } type PageMeta interface { diff --git a/internal/domain/site/entity/sitefields.go b/internal/domain/site/entity/sitefields.go index 9bcb1d4..76fe2ed 100644 --- a/internal/domain/site/entity/sitefields.go +++ b/internal/domain/site/entity/sitefields.go @@ -117,7 +117,7 @@ func (s *Site) sitePage(p contenthub.Page) (*Page, error) { } func (s *Site) siteWeightedPage(p contenthub.OrdinalWeightPage) (*WeightedPage, error) { - sp, err := s.sitePage(p) + sp, err := s.sitePage(p.Page()) if err != nil { return nil, err }