shithub: hugo

Download patch

ref: fd924d1802cb9c20c2617b1c72dac6bc36560d61
parent: e908d955d25cc5a2a5c783de4de569399773e23e
author: Bjørn Erik Pedersen <[email protected]>
date: Thu Jun 22 16:39:55 EDT 2017

commands: Create default archetype on new site

See #3626

--- a/commands/new.go
+++ b/commands/new.go
@@ -152,10 +152,11 @@
 }
 
 func doNewSite(fs *hugofs.Fs, basepath string, force bool) error {
+	archeTypePath := filepath.Join(basepath, "archetypes")
 	dirs := []string{
 		filepath.Join(basepath, "layouts"),
 		filepath.Join(basepath, "content"),
-		filepath.Join(basepath, "archetypes"),
+		archeTypePath,
 		filepath.Join(basepath, "static"),
 		filepath.Join(basepath, "data"),
 		filepath.Join(basepath, "themes"),
@@ -189,6 +190,10 @@
 	}
 
 	createConfig(fs, basepath, configFormat)
+
+	// Create a defaul archetype file.
+	helpers.SafeWriteToDisk(filepath.Join(archeTypePath, "default.md"),
+		strings.NewReader(create.ArchetypeTemplateTemplate), fs.Source)
 
 	jww.FEEDBACK.Printf("Congratulations! Your new Hugo site is created in %s.\n\n", basepath)
 	jww.FEEDBACK.Println(nextStepsText())
--- a/create/content_template_handler.go
+++ b/create/content_template_handler.go
@@ -48,11 +48,13 @@
 }
 
 const (
-	archetypeTemplateTemplate = `---
+	ArchetypeTemplateTemplate = `---
 title: "{{ replace .TranslationBaseName "-" " " | title }}"
 date: {{ .Date }}
 draft: true
----`
+---
+
+`
 )
 
 func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFilename string) ([]byte, error) {
@@ -75,7 +77,7 @@
 
 	if archetypeFilename == "" {
 		// TODO(bep) archetype revive the issue about wrong tpl funcs arg order
-		archetypeTemplate = []byte(archetypeTemplateTemplate)
+		archetypeTemplate = []byte(ArchetypeTemplateTemplate)
 	} else {
 		archetypeTemplate, err = afero.ReadFile(s.Fs.Source, archetypeFilename)
 		if err != nil {
@@ -105,7 +107,7 @@
 		s.Log.FEEDBACK.Println(fmt.Sprintf(`WARNING: date and/or title missing from archetype file %q. 
 From Hugo 0.24 this must be provided in the archetype file itself, if needed. Example:
 %s
-`, archetypeFilename, archetypeTemplateTemplate))
+`, archetypeFilename, ArchetypeTemplateTemplate))
 
 	}