sources := []source.ByteSource{
{Name: filepath.FromSlash("sect/doc1.en.md"), Content: []byte(`---
title: doc1
+weight: 1
slug: doc1-slug
tags:
- tag1
`)},
{Name: filepath.FromSlash("sect/doc1.fr.md"), Content: []byte(`---
title: doc1
+weight: 1
plaques:
- frtag1
- frtag2
`)},
{Name: filepath.FromSlash("sect/doc2.en.md"), Content: []byte(`---
title: doc2
+weight: 2
publishdate: "2000-01-02"
---
# doc2
`)},
{Name: filepath.FromSlash("sect/doc3.en.md"), Content: []byte(`---
title: doc3
+weight: 3
publishdate: "2000-01-03"
tags:
- tag2
`)},
{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte(`---
title: doc4
+weight: 4
plaques:
- frtag1
publishdate: "2000-01-05"
`)},
{Name: filepath.FromSlash("other/doc5.fr.md"), Content: []byte(`---
title: doc5
+weight: 5
publishdate: "2000-01-06"
---
# doc5
`)},
{Name: filepath.FromSlash("stats/future.fr.md"), Content: []byte(`---
title: future
+weight: 6
publishdate: "2100-01-06"
---
# Future
`)},
{Name: filepath.FromSlash("stats/expired.en.md"), Content: []byte(`---
title: expired
+weight: 7
publishdate: "2000-01-06"
expiryDate: "2001-01-06"
---
`)},
{Name: filepath.FromSlash("stats/future.en.md"), Content: []byte(`---
title: future
+weight: 6
publishdate: "2100-01-06"
---
# Future
`)},
{Name: filepath.FromSlash("stats/tax.nn.md"), Content: []byte(`---
title: Tax NN
+weight: 8
publishdate: "2000-01-06"
weight: 1001
lag:
`)},
{Name: filepath.FromSlash("stats/tax.nb.md"), Content: []byte(`---
title: Tax NB
+weight: 8
publishdate: "2000-01-06"
weight: 1002
lag:
d1 := time.Now()
d2 := d1.Add(-1 * time.Hour)
d3 := d1.Add(-2 * time.Hour)
+ d4 := d1.Add(-3 * time.Hour)
- p := createSortTestPages(3)
+ p := createSortTestPages(4)
// first by weight
- setSortVals([3]time.Time{d1, d2, d3}, [3]string{"b", "a", "c"}, [3]int{3, 2, 1}, p)
+ setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "c", "d"}, [4]int{4, 3, 2, 1}, p)
+ p.Sort()
+
+ assert.Equal(t, 1, p[0].Weight)
+
+ // Consider zero weight, issue #2673
+ setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "d", "c"}, [4]int{0, 0, 0, 1}, p)
p.Sort()
assert.Equal(t, 1, p[0].Weight)
// next by date
- setSortVals([3]time.Time{d3, d1, d2}, [3]string{"a", "b", "c"}, [3]int{1, 1, 1}, p)
+ setSortVals([4]time.Time{d3, d4, d1, d2}, [4]string{"a", "b", "c", "d"}, [4]int{1, 1, 1, 1}, p)
p.Sort()
assert.Equal(t, d1, p[0].Date)
// finally by link title
- setSortVals([3]time.Time{d3, d3, d3}, [3]string{"b", "c", "a"}, [3]int{1, 1, 1}, p)
+ setSortVals([4]time.Time{d3, d3, d3, d3}, [4]string{"b", "c", "a", "d"}, [4]int{1, 1, 1, 1}, p)
p.Sort()
assert.Equal(t, "al", p[0].LinkTitle())
assert.Equal(t, "bl", p[1].LinkTitle())
d1 := time.Now()
d2 := d1.Add(-2 * time.Hour)
d3 := d1.Add(-10 * time.Hour)
+ d4 := d1.Add(-20 * time.Hour)
- p := createSortTestPages(3)
+ p := createSortTestPages(4)
for i, this := range []struct {
sortFunc func(p Pages) Pages
{(Pages).ByWeight, func(p Pages) bool { return p[0].Weight == 1 }},
{(Pages).ByTitle, func(p Pages) bool { return p[0].Title == "ab" }},
{(Pages).ByLinkTitle, func(p Pages) bool { return p[0].LinkTitle() == "abl" }},
- {(Pages).ByDate, func(p Pages) bool { return p[0].Date == d3 }},
- {(Pages).ByPublishDate, func(p Pages) bool { return p[0].PublishDate == d3 }},
- {(Pages).ByExpiryDate, func(p Pages) bool { return p[0].ExpiryDate == d3 }},
- {(Pages).ByLastmod, func(p Pages) bool { return p[1].Lastmod == d2 }},
+ {(Pages).ByDate, func(p Pages) bool { return p[0].Date == d4 }},
+ {(Pages).ByPublishDate, func(p Pages) bool { return p[0].PublishDate == d4 }},
+ {(Pages).ByExpiryDate, func(p Pages) bool { return p[0].ExpiryDate == d4 }},
+ {(Pages).ByLastmod, func(p Pages) bool { return p[1].Lastmod == d3 }},
{(Pages).ByLength, func(p Pages) bool { return p[0].Content == "b_content" }},
} {
- setSortVals([3]time.Time{d1, d2, d3}, [3]string{"b", "ab", "cde"}, [3]int{3, 2, 1}, p)
+ setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "ab", "cde", "fg"}, [4]int{0, 3, 2, 1}, p)
sorted := this.sortFunc(p)
if !this.assertFunc(sorted) {
}
}
-func setSortVals(dates [3]time.Time, titles [3]string, weights [3]int, pages Pages) {
+func setSortVals(dates [4]time.Time, titles [4]string, weights [4]int, pages Pages) {
for i := range dates {
pages[i].Date = dates[i]
pages[i].Lastmod = dates[i]
Source: Source{File: *source.NewFile(filepath.FromSlash(fmt.Sprintf("/x/y/p%d.md", i)))},
}
w := 5
+
if i%2 == 0 {
w = 10
}