summaryrefslogtreecommitdiffstats
path: root/hugolib/pageSort.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-07-25 22:22:09 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-06 18:32:15 +0300
commitc4e7c37055a029a26d87ebeb21614efb3f0b0040 (patch)
tree55c05751d0734ace44783bc0b196873fd889d590 /hugolib/pageSort.go
parent06d12ab895a83fc8a9f94b23e533b25511bbb6d1 (diff)
Add Translations and AllTranslations methods to Page
Will revisit Node later.
Diffstat (limited to 'hugolib/pageSort.go')
-rw-r--r--hugolib/pageSort.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go
index 248e3ed5d..ec5e2c36d 100644
--- a/hugolib/pageSort.go
+++ b/hugolib/pageSort.go
@@ -56,6 +56,19 @@ var defaultPageSort = func(p1, p2 *Page) bool {
return p1.Weight < p2.Weight
}
+var languagePageSort = func(p1, p2 *Page) bool {
+ if p1.language.Weight == p2.language.Weight {
+ if p1.Date.Unix() == p2.Date.Unix() {
+ if p1.LinkTitle() == p2.LinkTitle() {
+ return (p1.FullFilePath() < p2.FullFilePath())
+ }
+ return (p1.LinkTitle() < p2.LinkTitle())
+ }
+ return p1.Date.Unix() > p2.Date.Unix()
+ }
+ return p1.language.Weight < p2.language.Weight
+}
+
func (ps *pageSorter) Len() int { return len(ps.pages) }
func (ps *pageSorter) Swap(i, j int) { ps.pages[i], ps.pages[j] = ps.pages[j], ps.pages[i] }
@@ -212,6 +225,20 @@ func (p Pages) ByLength() Pages {
return pages
}
+// ByLanguage sorts the Pages by the language's Weight.
+//
+// Adjacent invocactions on the same receiver will return a cached result.
+//
+// This may safely be executed in parallel.
+func (p Pages) ByLanguage() Pages {
+
+ key := "pageSort.ByLanguage"
+
+ pages, _ := spc.get(key, p, pageBy(languagePageSort).Sort)
+
+ return pages
+}
+
// Reverse reverses the order in Pages and returns a copy.
//
// Adjacent invocactions on the same receiver will return a cached result.