hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit b9bba2b977256642d00938e317cc2b743c418e6e
parent 0c2544608cfae1e272da252c383c8fa72634eed7
Author: spf13 <steve.francia@gmail.com>
Date:   Thu, 29 May 2014 18:40:16 -0400

Updating Convert to handle dates properly for yaml and json

Fix bug with YAML & JSON with handling dates with 'new' and 'convert'

Diffstat:
Mcommands/convert.go | 14++++++++++++++
Mcommands/hugo.go | 2+-
Mcommands/new.go | 6++++++
Mcreate/content.go | 4++++
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git 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)
diff --git a/commands/hugo.go b/commands/hugo.go
@@ -99,7 +99,7 @@ func InitializeConfig() {
 	viper.RegisterAlias("taxonomies", "indexes")
 
 	viper.SetDefault("Watch", false)
-	viper.SetDefault("MetadataFormat", "toml")
+	viper.SetDefault("MetaDataFormat", "toml")
 	viper.SetDefault("DisableRSS", false)
 	viper.SetDefault("DisableSitemap", false)
 	viper.SetDefault("ContentDir", "content")
diff --git a/commands/new.go b/commands/new.go
@@ -23,6 +23,7 @@ import (
 	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/parser"
 	jww "github.com/spf13/jwalterweatherman"
+	"github.com/spf13/viper"
 )
 
 var siteType string
@@ -33,6 +34,7 @@ var contentFrontMatter string
 
 func init() {
 	newSiteCmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "config & frontmatter format")
+	newCmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "frontmatter format")
 	newCmd.Flags().StringVarP(&contentType, "kind", "k", "", "Content type to create")
 	newCmd.AddCommand(newSiteCmd)
 	newCmd.AddCommand(newThemeCmd)
@@ -73,6 +75,10 @@ as you see fit.
 func NewContent(cmd *cobra.Command, args []string) {
 	InitializeConfig()
 
+	if cmd.Flags().Lookup("format").Changed {
+		viper.Set("MetaDataFormat", configFormat)
+	}
+
 	if len(args) < 1 {
 		cmd.Usage()
 		jww.FATAL.Fatalln("path needs to be provided")
diff --git a/create/content.go b/create/content.go
@@ -90,6 +90,10 @@ func NewContent(kind, name string) (err error) {
 		return err
 	}
 
+	if x := viper.GetString("MetaDataFormat"); x == "json" || x == "yaml" {
+		newmetadata["date"] = time.Now().Format(time.RFC3339)
+	}
+
 	page.Dir = viper.GetString("sourceDir")
 	page.SetSourceMetaData(newmetadata, parser.FormatToLeadRune(viper.GetString("MetaDataFormat")))