summaryrefslogtreecommitdiffhomepage
path: root/create/content.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2016-11-29 20:18:09 +0100
committerBjørn Erik Pedersen <[email protected]>2016-11-29 20:18:09 +0100
commit96018ab98c1153c9d882656abf99685f2fb7e0c4 (patch)
tree99347fbdc20f9f2eaf0fb2e954fcaa6a74e83417 /create/content.go
parent65d4d96e7f24a27f69acec07ea56d5ab3ddc63c3 (diff)
downloadhugo-96018ab98c1153c9d882656abf99685f2fb7e0c4.tar.gz
hugo-96018ab98c1153c9d882656abf99685f2fb7e0c4.zip
create: Fix archetype title and date handling
Fixes #2750
Diffstat (limited to 'create/content.go')
-rw-r--r--create/content.go24
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