diff --git a/frontmatter/frontmatter.go b/frontmatter/frontmatter.go index b813efa..999a3b3 100644 --- a/frontmatter/frontmatter.go +++ b/frontmatter/frontmatter.go @@ -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 diff --git a/pages/drops.go b/pages/drops.go index 8c43298..953a8d1 100644 --- a/pages/drops.go +++ b/pages/drops.go @@ -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(),