Adding support for ordering content in indexes by other than date (weighted indexes)

This commit is contained in:
spf13
2013-10-24 15:24:47 -07:00
parent 471fb1ff69
commit a5606b06ca
3 changed files with 86 additions and 7 deletions

View File

@@ -288,12 +288,16 @@ func (s *Site) BuildSiteMeta() (err error) {
s.Indexes[plural] = make(Index)
for _, p := range s.Pages {
vals := p.GetParam(plural)
weight := p.GetParam(plural + "_weight")
if weight == nil {
weight = 0
}
if vals != nil {
v, ok := vals.([]string)
if ok {
for _, idx := range v {
x := WeightedIndexEntry{0, p}
x := WeightedIndexEntry{weight.(int), p}
s.Indexes[plural].Add(idx, x)
}
@@ -403,7 +407,7 @@ func (s *Site) RenderIndexes() error {
n.RSSlink = permalink(s, url+".xml")
n.Date = o[0].Page.Date
n.Data[singular] = o
n.Data["Pages"] = o
n.Data["Pages"] = o.Pages()
layout := "indexes/" + singular + ".html"
var base string
@@ -458,7 +462,7 @@ func (s *Site) RenderLists() error {
n.Permalink = permalink(s, n.Url)
n.RSSlink = permalink(s, section+".xml")
n.Date = data[0].Page.Date
n.Data["Pages"] = data
n.Data["Pages"] = data.Pages()
layout := "indexes/" + section + ".html"
err := s.render(n, section, layout, "_default/indexes.html")