create: Allow empty dates in archetype in new

To make it behave the same as Hugo 0.17.
This commit is contained in:
Bjørn Erik Pedersen 2016-12-15 09:27:30 +01:00
parent e4ebe0d5bf
commit ef03c6f954
2 changed files with 8 additions and 0 deletions

View file

@ -110,6 +110,9 @@ func createMetadata(archetype parser.Page, name string) (map[string]interface{},
var date time.Time var date time.Time
for k, v := range metadata { for k, v := range metadata {
if v == "" {
continue
}
lk := strings.ToLower(k) lk := strings.ToLower(k)
switch lk { switch lk {
case "date": case "date":

View file

@ -42,6 +42,7 @@ func TestNewContent(t *testing.T) {
expected []string expected []string
}{ }{
{"post", "post/sample-1.md", []string{`title = "Post Arch title"`, `test = "test1"`, "date = \"2015-01-12T19:20:04-07:00\""}}, {"post", "post/sample-1.md", []string{`title = "Post Arch title"`, `test = "test1"`, "date = \"2015-01-12T19:20:04-07:00\""}},
{"emptydate", "post/sample-ed.md", []string{`title = "Empty Date Arch title"`, `test = "test1"`}},
{"stump", "stump/sample-2.md", []string{`title = "sample 2"`}}, // no archetype file {"stump", "stump/sample-2.md", []string{`title = "sample 2"`}}, // no archetype file
{"", "sample-3.md", []string{`title = "sample 3"`}}, // no archetype {"", "sample-3.md", []string{`title = "sample 3"`}}, // no archetype
{"product", "product/sample-4.md", []string{`title = "sample 4"`}}, // empty archetype front matter {"product", "product/sample-4.md", []string{`title = "sample 4"`}}, // empty archetype front matter
@ -105,6 +106,10 @@ func initFs() error {
path: filepath.Join("archetypes", "product.md"), path: filepath.Join("archetypes", "product.md"),
content: "+++\n+++\n", content: "+++\n+++\n",
}, },
{
path: filepath.Join("archetypes", "emptydate.md"),
content: "+++\ndate =\"\"\ntitle = \"Empty Date Arch title\"\ntest = \"test1\"\n+++\n",
},
} { } {
f, err := hugofs.Source().Create(v.path) f, err := hugofs.Source().Create(v.path)
if err != nil { if err != nil {