Added support for indexes of indexes & ordered indexes

This commit is contained in:
spf13
2013-08-03 03:09:28 -04:00
parent ddad1e04ac
commit 52c089ffbd
2 changed files with 38 additions and 13 deletions

View File

@@ -45,7 +45,7 @@ type Site struct {
type SiteInfo struct {
BaseUrl template.URL
Indexes *OrderedIndexList
Indexes OrderedIndexList
Recent *Pages
LastChange time.Time
Title string
@@ -94,6 +94,7 @@ func (site *Site) Render() {
site.AbsUrlify()
site.timer.Step("absolute URLify")
site.RenderIndexes()
site.RenderIndexesIndexes()
site.timer.Step("render and write indexes")
site.RenderLists()
site.timer.Step("render and write lists")
@@ -263,6 +264,7 @@ func (s *Site) BuildSiteMeta() (err error) {
}
s.Info.Indexes = s.Indexes.BuildOrderedIndexList()
if len(s.Pages) == 0 {
return errors.New(fmt.Sprintf("Unable to build site metadata, no pages found in directory %s", s.c.ContentDir))
}
@@ -352,6 +354,27 @@ func (s *Site) RenderIndexes() {
}
}
func (s *Site) RenderIndexesIndexes() {
layout := "indexes" + slash + "index.html"
if s.Tmpl.Lookup(layout) != nil {
for singular, plural := range s.c.Indexes {
n := s.NewNode()
n.Title = strings.Title(plural)
url := Urlize(plural)
n.Url = url + "/index.html"
n.Permalink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string(n.Url)))
n.Data["Singular"] = singular
n.Data["Plural"] = plural
n.Data["Index"] = s.Indexes[plural]
n.Data["OrderedIndex"] = s.Info.Indexes[plural]
fmt.Println(s.Info.Indexes)
x := s.RenderThing(n, layout)
s.WritePublic(plural+slash+"index.html", x.Bytes())
}
}
}
func (s *Site) RenderLists() {
for section, data := range s.Sections {
n := s.NewNode()