-
Notifications
You must be signed in to change notification settings - Fork 13
/
drop.go
86 lines (77 loc) · 1.94 KB
/
drop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package site
import (
"log"
"time"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/plugins"
"github.com/osteele/gojekyll/templates"
"github.com/osteele/liquid"
)
// ToLiquid returns the site variable for template evaluation.
func (s *Site) ToLiquid() interface{} {
s.dropOnce.Do(func() {
if err := s.initializeDrop(); err != nil {
log.Fatalf("ToLiquid failed: %s\n", err)
}
})
return liquid.IterationKeyedMap(s.drop)
}
func (s *Site) initializeDrop() error {
var docs []Page
for _, c := range s.Collections {
docs = append(docs, c.Pages()...)
}
drop := templates.MergeVariableMaps(s.cfg.Variables(), map[string]interface{}{
"collections": s.collectionDrops(),
"data": s.data,
"documents": docs,
"html_files": s.htmlFiles(),
"html_pages": s.htmlPages(),
"pages": s.nonCollectionPages,
"static_files": s.staticFiles(),
// TODO read time from _config, if it's available
"time": time.Now(),
})
for _, c := range s.Collections {
drop[c.Name] = c.Pages()
}
s.drop = drop
s.setPostVariables()
return s.runHooks(func(h plugins.Plugin) error {
return h.ModifySiteDrop(s, drop)
})
}
// The following functions are only used in the drop.
//
// Since the drop is cached, there's no effort to cache these too.
func (s *Site) collectionDrops() []interface{} {
var drops []interface{}
for _, c := range s.Collections {
drops = append(drops, c.ToLiquid())
}
return drops
}
func (s *Site) htmlFiles() (result []*pages.StaticFile) {
for _, p := range s.staticFiles() {
if p.OutputExt() == ".html" {
result = append(result, p)
}
}
return
}
func (s *Site) htmlPages() (result []Page) {
for _, p := range s.nonCollectionPages {
if p.OutputExt() == ".html" {
result = append(result, p)
}
}
return
}
func (s *Site) staticFiles() (result []*pages.StaticFile) {
for _, d := range s.docs {
if sd, ok := d.(*pages.StaticFile); ok {
result = append(result, sd)
}
}
return
}