1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-22 16:31:14 +01:00

Define page.date

This commit is contained in:
Oliver Steele 2017-08-20 16:51:26 -04:00
parent a8e5e47197
commit 1fa322bb69
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package frontmatter
import (
"fmt"
"reflect"
"sort"
"strings"
@ -21,11 +22,22 @@ func (fm FrontMatter) Bool(k string, defaultValue bool) bool {
return defaultValue
}
// String returns m[k] if it's a string; else defaultValue.
// Get returns m[k] if present; else defaultValue.
func (fm FrontMatter) Get(k string, defaultValue interface{}) interface{} {
if val, found := fm[k]; found {
return val
}
return defaultValue
}
// String returns m[k] if it's a string or can be stringified; else defaultValue.
func (fm FrontMatter) String(k string, defaultValue string) string {
if val, found := fm[k]; found {
if v, ok := val.(string); ok {
switch v := val.(type) {
case string:
return v
case fmt.Stringer:
return v.String()
}
}
return defaultValue

View File

@ -46,6 +46,7 @@ func (p *page) ToLiquid() interface{} {
)
data := map[string]interface{}{
"content": p.maybeContent(),
"date": fm.Get("date", p.fileModTime),
"excerpt": p.Excerpt(),
"path": relpath,
"url": p.Permalink(),