mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-20 10:44:20 +00:00
More work on indexes
This commit is contained in:
parent
bc7c9221f3
commit
a7dae30a8f
2 changed files with 20 additions and 8 deletions
|
@ -28,6 +28,7 @@ type IndexedPages []WeightedIndexEntry
|
||||||
func (p IndexedPages) Len() int { return len(p) }
|
func (p IndexedPages) Len() int { return len(p) }
|
||||||
func (p IndexedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
func (p IndexedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||||
func (p IndexedPages) Sort() { sort.Sort(p) }
|
func (p IndexedPages) Sort() { sort.Sort(p) }
|
||||||
|
func (p IndexedPages) Count() int { return len(p) }
|
||||||
func (p IndexedPages) Less(i, j int) bool {
|
func (p IndexedPages) Less(i, j int) bool {
|
||||||
if p[i].Weight == p[j].Weight {
|
if p[i].Weight == p[j].Weight {
|
||||||
return p[i].Page.Date.Unix() > p[j].Page.Date.Unix()
|
return p[i].Page.Date.Unix() > p[j].Page.Date.Unix()
|
||||||
|
@ -59,17 +60,17 @@ func (i Index) Add(key string, w WeightedIndexEntry) {
|
||||||
i[key] = append(i[key], w)
|
i[key] = append(i[key], w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Index) IndexArray() []IndexEntry {
|
func (i Index) IndexArray() IndexEntries {
|
||||||
ies := make([]IndexEntry, len(i))
|
ies := make([]IndexEntry, len(i))
|
||||||
count := 0
|
count := 0
|
||||||
for k, v := range i {
|
for k, v := range i {
|
||||||
ies[count] = IndexEntry{Name: k, Pages: v}
|
ies[count] = IndexEntry{Name: k, WeightedPages: v}
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
return ies
|
return ies
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Index) Alphabetical() []IndexEntry {
|
func (i Index) Alphabetical() IndexEntries {
|
||||||
name := func(i1, i2 *IndexEntry) bool {
|
name := func(i1, i2 *IndexEntry) bool {
|
||||||
return i1.Name < i2.Name
|
return i1.Name < i2.Name
|
||||||
}
|
}
|
||||||
|
@ -79,9 +80,9 @@ func (i Index) Alphabetical() []IndexEntry {
|
||||||
return ia
|
return ia
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Index) ByCount() []IndexEntry {
|
func (i Index) ByCount() IndexEntries {
|
||||||
count := func(i1, i2 *IndexEntry) bool {
|
count := func(i1, i2 *IndexEntry) bool {
|
||||||
return len(i1.Pages) < len(i2.Pages)
|
return len(i1.WeightedPages) > len(i2.WeightedPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
ia := i.IndexArray()
|
ia := i.IndexArray()
|
||||||
|
@ -90,10 +91,20 @@ func (i Index) ByCount() []IndexEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IndexEntry struct {
|
type IndexEntry struct {
|
||||||
Name string
|
Name string
|
||||||
Pages IndexedPages
|
WeightedPages IndexedPages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ie IndexEntry) Pages() []*Page {
|
||||||
|
return ie.WeightedPages.Pages()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ie IndexEntry) Count() int {
|
||||||
|
return len(ie.WeightedPages)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IndexEntries []IndexEntry
|
||||||
|
|
||||||
type By func(i1, i2 *IndexEntry) bool
|
type By func(i1, i2 *IndexEntry) bool
|
||||||
|
|
||||||
func (by By) Sort(indexEntrys []IndexEntry) {
|
func (by By) Sort(indexEntrys []IndexEntry) {
|
||||||
|
|
|
@ -452,7 +452,8 @@ func (s *Site) RenderIndexesIndexes() (err error) {
|
||||||
n.Data["Singular"] = singular
|
n.Data["Singular"] = singular
|
||||||
n.Data["Plural"] = plural
|
n.Data["Plural"] = plural
|
||||||
n.Data["Index"] = s.Indexes[plural]
|
n.Data["Index"] = s.Indexes[plural]
|
||||||
n.Data["OrderedIndex"] = s.Info.Indexes[plural]
|
// keep the following just for legacy reasons
|
||||||
|
n.Data["OrderedIndex"] = s.Indexes[plural]
|
||||||
|
|
||||||
err := s.render(n, plural+"/index.html", layout)
|
err := s.render(n, plural+"/index.html", layout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue