Reimplement and simplify Hugo's template system

See #13541 for details.

Fixes #13545
Fixes #13515
Closes #7964
Closes #13365
Closes #12988
Closes #4891
This commit is contained in:
Bjørn Erik Pedersen
2025-04-06 19:55:35 +02:00
parent 812ea0b325
commit 83cfdd78ca
138 changed files with 5342 additions and 4396 deletions

View File

@@ -13,7 +13,9 @@
package doctree
var _ Tree[string] = (*TreeShiftTree[string])(nil)
import "iter"
var _ TreeThreadSafe[string] = (*TreeShiftTree[string])(nil)
type TreeShiftTree[T comparable] struct {
// This tree is shiftable in one dimension.
@@ -26,16 +28,16 @@ type TreeShiftTree[T comparable] struct {
zero T
// Will be of length equal to the length of the dimension.
trees []*SimpleTree[T]
trees []*SimpleThreadSafeTree[T]
}
func NewTreeShiftTree[T comparable](d, length int) *TreeShiftTree[T] {
if length <= 0 {
panic("length must be > 0")
}
trees := make([]*SimpleTree[T], length)
trees := make([]*SimpleThreadSafeTree[T], length)
for i := range length {
trees[i] = NewSimpleTree[T]()
trees[i] = NewSimpleThreadSafeTree[T]()
}
return &TreeShiftTree[T]{d: d, trees: trees}
}
@@ -91,6 +93,14 @@ func (t *TreeShiftTree[T]) WalkPrefixRaw(lockType LockType, s string, f func(s s
return nil
}
func (t *TreeShiftTree[T]) WalkPath(lockType LockType, s string, f func(s string, v T) (bool, error)) error {
return t.trees[t.v].WalkPath(lockType, s, f)
}
func (t *TreeShiftTree[T]) All(lockType LockType) iter.Seq2[string, T] {
return t.trees[t.v].All(lockType)
}
func (t *TreeShiftTree[T]) LenRaw() int {
var count int
for _, tt := range t.trees {