1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-06 03:28:15 +01:00
gojekyll/site/drop.go

92 lines
2.0 KiB
Go
Raw Normal View History

2017-07-04 15:09:36 +02:00
package site
2017-07-03 16:39:55 +02:00
import (
"time"
2017-07-07 18:24:00 +02:00
"github.com/osteele/gojekyll/pages"
2017-07-03 16:39:55 +02:00
"github.com/osteele/gojekyll/templates"
2017-07-05 17:35:20 +02:00
"github.com/osteele/liquid/evaluator"
2017-07-03 16:39:55 +02:00
)
// ToLiquid returns the site variable for template evaluation.
func (s *Site) ToLiquid() interface{} {
2017-07-09 22:09:03 +02:00
if len(s.drop) > 0 {
return s.drop
}
s.Lock()
defer s.Unlock()
2017-07-03 16:39:55 +02:00
if len(s.drop) == 0 {
2017-07-09 22:09:03 +02:00
s.initializeDrop()
2017-07-03 16:39:55 +02:00
}
return s.drop
}
// MarshalYAML is part of the yaml.Marshaler interface
// The variables subcommand uses this.
func (s *Site) MarshalYAML() (interface{}, error) {
return s.ToLiquid(), nil
}
func (s *Site) initializeDrop() {
vars := templates.MergeVariableMaps(s.config.Variables, map[string]interface{}{
2017-07-07 21:48:31 +02:00
"data": s.data,
"documents": s.docs,
2017-07-09 20:05:46 +02:00
"html_files": s.htmlFiles(),
2017-07-07 18:24:00 +02:00
"html_pages": s.htmlPages(),
"pages": s.Pages(),
2017-07-09 20:05:46 +02:00
"static_files": s.staticFiles(),
2017-07-07 21:48:31 +02:00
// TODO read time from _config, if it's available
"time": time.Now(),
2017-07-03 16:39:55 +02:00
})
collections := []interface{}{}
for _, c := range s.Collections {
vars[c.Name] = c.Pages()
collections = append(collections, c.ToLiquid())
}
2017-07-05 17:35:20 +02:00
evaluator.SortByProperty(collections, "label", true)
2017-07-03 16:39:55 +02:00
vars["collections"] = collections
s.drop = vars
s.setPostVariables()
}
func (s *Site) setPageContent() error {
for _, c := range s.Collections {
2017-07-10 19:23:51 +02:00
if err := c.SetPageContent(); err != nil {
2017-07-03 16:39:55 +02:00
return err
}
}
return nil
}
2017-07-07 18:24:00 +02:00
2017-07-09 20:05:46 +02: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 18:24:00 +02: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 20:05:46 +02: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
}