mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	hugolib: Add sort ByExpiryDate function
This commit is contained in:
		
				
					committed by
					
						
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							6472f158a4
						
					
				
				
					commit
					091915c75d
				
			@@ -158,6 +158,24 @@ func (p Pages) ByPublishDate() Pages {
 | 
				
			|||||||
	return pages
 | 
						return pages
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ByExpiryDate sorts the Pages by publish date and returns a copy.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Adjacent invocactions on the same receiver will return a cached result.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// This may safely be executed  in parallel.
 | 
				
			||||||
 | 
					func (p Pages) ByExpiryDate() Pages {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						key := "pageSort.ByExpiryDate"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						expDate := func(p1, p2 *Page) bool {
 | 
				
			||||||
 | 
							return p1.ExpiryDate.Unix() < p2.ExpiryDate.Unix()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pages, _ := spc.get(key, p, pageBy(expDate).Sort)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return pages
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ByLastmod sorts the Pages by the last modification date and returns a copy.
 | 
					// ByLastmod sorts the Pages by the last modification date and returns a copy.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Adjacent invocactions on the same receiver will return a cached result.
 | 
					// Adjacent invocactions on the same receiver will return a cached result.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,6 +68,7 @@ func TestSortByN(t *testing.T) {
 | 
				
			|||||||
		{(Pages).ByLinkTitle, func(p Pages) bool { return p[0].LinkTitle() == "abl" }},
 | 
							{(Pages).ByLinkTitle, func(p Pages) bool { return p[0].LinkTitle() == "abl" }},
 | 
				
			||||||
		{(Pages).ByDate, func(p Pages) bool { return p[0].Date == d3 }},
 | 
							{(Pages).ByDate, func(p Pages) bool { return p[0].Date == d3 }},
 | 
				
			||||||
		{(Pages).ByPublishDate, func(p Pages) bool { return p[0].PublishDate == 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).ByLastmod, func(p Pages) bool { return p[1].Lastmod == d2 }},
 | 
				
			||||||
		{(Pages).ByLength, func(p Pages) bool { return p[0].Content == "b_content" }},
 | 
							{(Pages).ByLength, func(p Pages) bool { return p[0].Content == "b_content" }},
 | 
				
			||||||
	} {
 | 
						} {
 | 
				
			||||||
@@ -122,6 +123,7 @@ func setSortVals(dates [3]time.Time, titles [3]string, weights [3]int, pages Pag
 | 
				
			|||||||
		// make sure we compare apples and ... apples ...
 | 
							// make sure we compare apples and ... apples ...
 | 
				
			||||||
		pages[len(dates)-1-i].linkTitle = pages[i].Title + "l"
 | 
							pages[len(dates)-1-i].linkTitle = pages[i].Title + "l"
 | 
				
			||||||
		pages[len(dates)-1-i].PublishDate = dates[i]
 | 
							pages[len(dates)-1-i].PublishDate = dates[i]
 | 
				
			||||||
 | 
							pages[len(dates)-1-i].ExpiryDate = dates[i]
 | 
				
			||||||
		pages[len(dates)-1-i].Content = template.HTML(titles[i] + "_content")
 | 
							pages[len(dates)-1-i].Content = template.HTML(titles[i] + "_content")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	lastLastMod := pages[2].Lastmod
 | 
						lastLastMod := pages[2].Lastmod
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user