diff options
Diffstat (limited to 'create/content.go')
-rw-r--r-- | create/content.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/create/content.go b/create/content.go index fb9ef7a04..783e21449 100644 --- a/create/content.go +++ b/create/content.go @@ -48,7 +48,7 @@ func NewContent(fs afero.Fs, kind, name string) (err error) { } } if location == "" || err != nil { - by = []byte("+++\n title = \"title\"\n draft = true \n+++\n") + by = []byte("+++\ndraft = true \n+++\n") } psr, err := parser.ReadFrom(bytes.NewReader(by)) @@ -107,12 +107,19 @@ func createMetadata(archetype parser.Page, name string) (map[string]interface{}, return nil, err } - for k := range metadata { - switch strings.ToLower(k) { + var date time.Time + + for k, v := range metadata { + lk := strings.ToLower(k) + switch lk { case "date": - metadata[k] = time.Now() + date, err = cast.ToTimeE(v) + if err != nil { + return nil, err + } case "title": - metadata[k] = helpers.MakeTitle(helpers.Filename(name)) + // Use the archetype title as is + metadata[lk] = cast.ToString(v) } } @@ -130,15 +137,18 @@ func createMetadata(archetype parser.Page, name string) (map[string]interface{}, } if !caseimatch(metadata, "date") { - metadata["date"] = time.Now() + date = time.Now() } if !caseimatch(metadata, "title") { metadata["title"] = helpers.MakeTitle(helpers.Filename(name)) } + // TOD(bep) what is this? if x := parser.FormatSanitize(viper.GetString("metaDataFormat")); x == "json" || x == "yaml" || x == "toml" { - metadata["date"] = time.Now().Format(time.RFC3339) + metadata["date"] = date.Format(time.RFC3339) + } else { + metadata["date"] = date } return metadata, nil |