mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
resources/page: Implement compare.ProbablyEqer for the core slices
Fixes #5808
This commit is contained in:
@@ -17,11 +17,14 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gohugoio/hugo/compare"
|
||||
|
||||
"github.com/gohugoio/hugo/resources/resource"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.ResourcesConverter = Pages{}
|
||||
_ compare.ProbablyEqer = Pages{}
|
||||
)
|
||||
|
||||
// Pages is a slice of pages. This is the most common list type in Hugo.
|
||||
@@ -95,6 +98,33 @@ func (p Pages) Len() int {
|
||||
return len(p)
|
||||
}
|
||||
|
||||
// ProbablyEq wraps comare.ProbablyEqer
|
||||
func (pages Pages) ProbablyEq(other interface{}) bool {
|
||||
otherPages, ok := other.(Pages)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(pages) != len(otherPages) {
|
||||
return false
|
||||
}
|
||||
|
||||
step := 1
|
||||
|
||||
for i := 0; i < len(pages); i += step {
|
||||
if !pages[i].Eq(otherPages[i]) {
|
||||
return false
|
||||
}
|
||||
|
||||
if i > 50 {
|
||||
// This is most likely the same.
|
||||
step = 50
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ps Pages) removeFirstIfFound(p Page) Pages {
|
||||
ii := -1
|
||||
for i, pp := range ps {
|
||||
|
Reference in New Issue
Block a user