summaryrefslogtreecommitdiffstats
path: root/commands/convert.go
diff options
context:
space:
mode:
authorspf13 <steve.francia@gmail.com>2014-05-29 18:40:16 -0400
committerspf13 <steve.francia@gmail.com>2014-05-29 18:45:19 -0400
commitb9bba2b977256642d00938e317cc2b743c418e6e (patch)
treea975942afdd4bab9d94b9984001aef899abca27d /commands/convert.go
parent0c2544608cfae1e272da252c383c8fa72634eed7 (diff)
Updating Convert to handle dates properly for yaml and json
Fix bug with YAML & JSON with handling dates with 'new' and 'convert'
Diffstat (limited to 'commands/convert.go')
-rw-r--r--commands/convert.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/commands/convert.go b/commands/convert.go
index f093d0e1a..9d79a53ad 100644
--- a/commands/convert.go
+++ b/commands/convert.go
@@ -16,7 +16,9 @@ package commands
import (
"fmt"
"path"
+ "time"
+ "github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/hugo/hugolib"
"github.com/spf13/hugo/parser"
@@ -114,6 +116,18 @@ func convertContents(mark rune) (err error) {
return err
}
+ // better handling of dates in formats that don't have support for them
+ if mark == parser.FormatToLeadRune("json") || mark == parser.FormatToLeadRune("yaml") {
+ newmetadata := cast.ToStringMap(metadata)
+ for k, v := range newmetadata {
+ switch vv := v.(type) {
+ case time.Time:
+ newmetadata[k] = vv.Format(time.RFC3339)
+ }
+ }
+ metadata = newmetadata
+ }
+
page.Dir = file.Dir
page.SetSourceContent(psr.Content())
page.SetSourceMetaData(metadata, mark)