import (
"fmt"
"path"
+ "time"
+ "github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/hugo/hugolib"
"github.com/spf13/hugo/parser"
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)
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")
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
jww "github.com/spf13/jwalterweatherman"
+ "github.com/spf13/viper"
)
var siteType 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)
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")
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")))