1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-23 05:01:14 +01:00
gojekyll/site/drop.go

79 lines
1.8 KiB
Go
Raw Normal View History

2017-07-04 09:09:36 -04:00
package site
2017-07-03 10:39:55 -04:00
import (
"log"
2017-07-03 10:39:55 -04:00
"time"
2017-07-07 12:24:00 -04:00
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/plugins"
2017-07-03 10:39:55 -04:00
"github.com/osteele/gojekyll/templates"
2017-07-05 11:35:20 -04:00
"github.com/osteele/liquid/evaluator"
2017-07-03 10:39:55 -04:00
)
// ToLiquid returns the site variable for template evaluation.
func (s *Site) ToLiquid() interface{} {
s.dropOnce.Do(func() {
if err := s.initializeDrop(); err != nil {
2017-08-03 15:52:41 +02:00
log.Fatalf("ToLiquid failed: %s\n", err)
}
2017-08-03 15:52:41 +02:00
})
2017-07-03 10:39:55 -04:00
return s.drop
}
func (s *Site) initializeDrop() error {
drop := templates.MergeVariableMaps(s.config.Variables, map[string]interface{}{
2017-07-07 15:48:31 -04:00
"data": s.data,
"documents": s.docs,
2017-07-09 14:05:46 -04:00
"html_files": s.htmlFiles(),
2017-07-07 12:24:00 -04:00
"html_pages": s.htmlPages(),
"pages": s.Pages(),
2017-07-09 14:05:46 -04:00
"static_files": s.staticFiles(),
2017-07-07 15:48:31 -04:00
// TODO read time from _config, if it's available
"time": time.Now(),
2017-07-03 10:39:55 -04:00
})
collections := []interface{}{}
for _, c := range s.Collections {
drop[c.Name] = c.Pages()
2017-07-03 10:39:55 -04:00
collections = append(collections, c.ToLiquid())
}
2017-07-05 11:35:20 -04:00
evaluator.SortByProperty(collections, "label", true)
drop["collections"] = collections
s.drop = drop
2017-07-03 10:39:55 -04:00
s.setPostVariables()
return s.runHooks(func(h plugins.Plugin) error {
return h.ModifySiteDrop(s, drop)
})
2017-07-03 10:39:55 -04:00
}
2017-07-09 14:05:46 -04:00
// The following functions are only used in the drop, therefore they're
// non-public and they're listed here.
//
// Since the drop is cached, there's no effort to cache these too.
func (s *Site) htmlFiles() (out []*pages.StaticFile) {
for _, p := range s.staticFiles() {
if p.OutputExt() == ".html" {
out = append(out, p)
}
}
return
}
2017-07-07 12:24:00 -04:00
func (s *Site) htmlPages() (out []pages.Page) {
for _, p := range s.Pages() {
if p.OutputExt() == ".html" {
out = append(out, p)
}
}
return
}
2017-07-09 14:05:46 -04:00
func (s *Site) staticFiles() (out []*pages.StaticFile) {
for _, d := range s.docs {
if sd, ok := d.(*pages.StaticFile); ok {
out = append(out, sd)
}
}
return
}