mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-27 07:44:40 +01:00
Implement site.categories
This commit is contained in:
parent
9b1d1d7790
commit
e7c0ac5fc8
@ -13,7 +13,7 @@ This is currently 5-30x faster than Jekyll, depending on the use of `{% highligh
|
||||
- [ ] Content
|
||||
- [x] Front Matter
|
||||
- [ ] Posts
|
||||
- [ ] Categories
|
||||
- [x] Categories
|
||||
- [ ] Tags
|
||||
- [ ] Drafts
|
||||
- [ ] Future
|
||||
|
@ -1,6 +1,7 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/osteele/gojekyll/templates"
|
||||
@ -21,7 +22,7 @@ func (s *Site) initializeSiteVariables() error {
|
||||
"data": s.data,
|
||||
// TODO read time from _config, if it's available
|
||||
"time": time.Now(),
|
||||
// TODO pages, static_files, html_pages, html_files, documents, categories.CATEGORY, tags.TAG
|
||||
// TODO pages, static_files, html_pages, html_files, documents, tags.TAG
|
||||
})
|
||||
return s.setCollectionVariables(false)
|
||||
}
|
||||
@ -34,11 +35,7 @@ func (s *Site) setCollectionVariables(includeContent bool) error {
|
||||
}
|
||||
s.siteVariables[c.Name] = pages
|
||||
if c.IsPostsCollection() {
|
||||
related := pages
|
||||
if len(related) > 10 {
|
||||
related = related[:10]
|
||||
}
|
||||
s.siteVariables["related_posts"] = related
|
||||
s.setPostVariables(pages)
|
||||
}
|
||||
}
|
||||
// Set these here instead of initializeSiteVariables so that they're
|
||||
@ -47,6 +44,34 @@ func (s *Site) setCollectionVariables(includeContent bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Site) setPostVariables(pages []interface{}) {
|
||||
var (
|
||||
related = pages
|
||||
categories = map[string][]interface{}{}
|
||||
tags = map[string][]interface{}{}
|
||||
)
|
||||
if len(related) > 10 {
|
||||
related = related[:10]
|
||||
}
|
||||
for _, p := range pages {
|
||||
b := p.(map[string]interface{})
|
||||
switch cs := b["categories"].(type) {
|
||||
case []interface{}:
|
||||
for _, c := range cs {
|
||||
key := fmt.Sprint(c)
|
||||
ps, found := categories[key]
|
||||
if !found {
|
||||
ps = []interface{}{}
|
||||
}
|
||||
categories[key] = append(ps, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
s.siteVariables["categories"] = categories
|
||||
s.siteVariables["tags"] = tags
|
||||
s.siteVariables["related_posts"] = related
|
||||
}
|
||||
|
||||
func (s *Site) setCollectionContent() error {
|
||||
return s.setCollectionVariables(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user