2017-08-10 17:18:36 +02:00
|
|
|
package site
|
|
|
|
|
2017-08-10 17:35:31 +02:00
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/osteele/gojekyll/collection"
|
|
|
|
)
|
|
|
|
|
2017-08-10 17:18:36 +02:00
|
|
|
// Render renders the site's pages.
|
|
|
|
func (s *Site) Render() error {
|
2017-08-10 17:35:31 +02:00
|
|
|
cols := make([]*collection.Collection, 0, len(s.Collections))
|
|
|
|
copy(cols, s.Collections)
|
|
|
|
sort.Sort(postsCollectionLast(cols))
|
|
|
|
for _, c := range cols {
|
2017-08-10 17:18:36 +02:00
|
|
|
if err := c.Render(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 17:45:46 +02:00
|
|
|
for _, c := range s.nonCollectionPages {
|
|
|
|
if err := c.Render(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 17:18:36 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) ensureRendered() (err error) {
|
|
|
|
s.renderOnce.Do(func() {
|
|
|
|
err = s.initializeRenderingPipeline()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = s.Render()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2017-08-10 17:35:31 +02:00
|
|
|
|
|
|
|
type postsCollectionLast []*collection.Collection
|
|
|
|
|
|
|
|
func (d postsCollectionLast) Len() int {
|
|
|
|
return len([]*collection.Collection(d))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d postsCollectionLast) Less(i, j int) bool {
|
|
|
|
array := []*collection.Collection(d)
|
|
|
|
a, b := array[i], array[j]
|
|
|
|
switch {
|
|
|
|
case a.IsPostsCollection():
|
|
|
|
return false
|
|
|
|
case b.IsPostsCollection():
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return a.Name < b.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d postsCollectionLast) Swap(i, j int) {
|
|
|
|
array := []*collection.Collection(d)
|
|
|
|
a, b := array[i], array[j]
|
|
|
|
array[i], array[j] = b, a
|
|
|
|
}
|