1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 12:17:48 +01:00
gojekyll/plugins/default_layout.go

49 lines
901 B
Go
Raw Normal View History

2017-09-02 18:10:35 +02:00
package plugins
func init() {
register("jekyll-default-layout", jekyllDefaultLayout{})
}
type jekyllDefaultLayout struct{ plugin }
const (
defaultLayout int = iota
pageLayout
postLayout
homeLayout
)
var layoutNames = []string{"default", "post", "page", "home"}
func (p jekyllDefaultLayout) layoutNames(s Site) []string {
var ln string
names := make([]string, len(layoutNames))
for i, n := range layoutNames {
// fmt.Println("examine", i, n, names)
if s.HasLayout(n) {
ln = n
}
names[i] = ln
}
return names
}
func (p jekyllDefaultLayout) PostInitPage(s Site, pg Page) error {
fm := pg.FrontMatter()
if fm["layout"] != nil {
return nil
}
layoutNames := p.layoutNames(s)
ln := layoutNames[pageLayout]
switch {
case pg.IsPost():
ln = layoutNames[postLayout]
2017-09-02 19:53:50 +02:00
case pg.URL() == "/":
2017-09-02 18:10:35 +02:00
ln = layoutNames[homeLayout]
}
if ln != "" {
fm["layout"] = ln
}
return nil
}