Skip to content

Commit

Permalink
create: Fix archetype regression when no archetype file
Browse files Browse the repository at this point in the history
Fixes #3626
  • Loading branch information
bep committed Jun 24, 2017
1 parent 4c3fa73 commit 4294dd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
18 changes: 11 additions & 7 deletions create/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions create/content_template_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions create/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4294dd8

Please sign in to comment.