diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-22 20:30:01 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-22 22:00:42 +0200 |
commit | e908d955d25cc5a2a5c783de4de569399773e23e (patch) | |
tree | b87874c5ad69ed59ea7d8cd9e62da217f6790203 | |
parent | 8b620f7a8a729943d279e20a3250304e7a7713cf (diff) |
create: Fix archetype regression when no archetype file
Fixes #3626
-rw-r--r-- | create/content.go | 18 | ||||
-rw-r--r-- | create/content_template_handler.go | 10 | ||||
-rw-r--r-- | create/content_test.go | 4 |
3 files changed, 18 insertions, 14 deletions
diff --git a/create/content.go b/create/content.go index e584df73e..8af417294 100644 --- a/create/content.go +++ b/create/content.go @@ -36,15 +36,19 @@ func NewContent( archetypeFilename := findArchetype(ps, kind, ext) - f, err := ps.Fs.Source.Open(archetypeFilename) - if err != nil { - return err - } - defer f.Close() // Building the sites can be expensive, so only do it if really needed. siteUsed := false - if helpers.ReaderContains(f, []byte(".Site")) { - siteUsed = true + + if archetypeFilename != "" { + f, err := ps.Fs.Source.Open(archetypeFilename) + if err != nil { + return err + } + defer f.Close() + + if helpers.ReaderContains(f, []byte(".Site")) { + siteUsed = true + } } s, err := siteFactory(targetPath, siteUsed) diff --git a/create/content_template_handler.go b/create/content_template_handler.go index 48e7f3b4b..d8c1fc71c 100644 --- a/create/content_template_handler.go +++ b/create/content_template_handler.go @@ -48,11 +48,11 @@ type ArchetypeFileData struct { } const ( - archetypeTemplateTemplate = `+++ -title = "{{ replace .TranslationBaseName "-" " " | title }}" -date = {{ .Date }} -draft = true -+++` + archetypeTemplateTemplate = `--- +title: "{{ replace .TranslationBaseName "-" " " | title }}" +date: {{ .Date }} +draft: true +---` ) func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFilename string) ([]byte, error) { diff --git a/create/content_test.go b/create/content_test.go index e8857baf2..bd7c34a1d 100644 --- a/create/content_test.go +++ b/create/content_test.go @@ -46,8 +46,8 @@ func TestNewContent(t *testing.T) { {"post", "post/sample-1.md", []string{`title = "Post Arch title"`, `test = "test1"`, "date = \"2015-01-12T19:20:04-07:00\""}}, {"post", "post/org-1.org", []string{`#+title: ORG-1`}}, {"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 - {"", "sample-3.md", []string{`title = "Sample 3"`}}, // no archetype + {"stump", "stump/sample-2.md", []string{`title: "Sample 2"`}}, // no archetype file + {"", "sample-3.md", []string{`title: "Sample 3"`}}, // no archetype {"product", "product/sample-4.md", []string{`title = "SAMPLE-4"`}}, // empty archetype front matter } |