summaryrefslogtreecommitdiffstats
path: root/create
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-26 09:41:24 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-26 12:16:28 +0200
commit78578632f545283741a01f024a6ccedc0b695a30 (patch)
tree67f666cdea850bc84e24fcf2b22c77ffddfdc301 /create
parent6b78b3810a800e315b57e2d907db9040cda36ac0 (diff)
Fix archetype handling of directories in theme
Fixes #5318
Diffstat (limited to 'create')
-rw-r--r--create/content.go10
-rw-r--r--create/content_test.go12
2 files changed, 18 insertions, 4 deletions
diff --git a/create/content.go b/create/content.go
index 388f2b4a0..31b7b2e4d 100644
--- a/create/content.go
+++ b/create/content.go
@@ -71,6 +71,7 @@ func NewContent(
siteUsed := false
if archetypeFilename != "" {
+
var err error
siteUsed, err = usesSiteVar(archetypeFs, archetypeFilename)
if err != nil {
@@ -130,7 +131,7 @@ func newContentFromDir(
// Just copy the file to destination.
in, err := sourceFs.Open(filename)
if err != nil {
- return err
+ return errors.Wrap(err, "failed to open non-content file")
}
targetFilename := filepath.Join(targetPath, strings.TrimPrefix(filename, archetypeDir))
@@ -158,11 +159,11 @@ func newContentFromDir(
content, err := executeArcheTypeAsTemplate(s, name, archetypeDir, targetFilename, filename)
if err != nil {
- return err
+ return errors.Wrap(err, "failed to execute archetype template")
}
if err := helpers.SafeWriteToDisk(targetFilename, bytes.NewReader(content), targetFs); err != nil {
- return err
+ return errors.Wrap(err, "failed to save results")
}
}
@@ -189,6 +190,7 @@ func mapArcheTypeDir(
var m archetypeMap
walkFn := func(filename string, fi os.FileInfo, err error) error {
+
if err != nil {
return err
}
@@ -216,7 +218,7 @@ func mapArcheTypeDir(
}
if err := helpers.SymbolicWalk(fs, archetypeDir, walkFn); err != nil {
- return m, err
+ return m, errors.Wrapf(err, "failed to walk archetype dir %q", archetypeDir)
}
return m, nil
diff --git a/create/content_test.go b/create/content_test.go
index 503c9da8d..e321900bc 100644
--- a/create/content_test.go
+++ b/create/content_test.go
@@ -93,6 +93,9 @@ func TestNewContentFromDir(t *testing.T) {
archetypeDir := filepath.Join("archetypes", "my-bundle")
assert.NoError(fs.Source.Mkdir(archetypeDir, 0755))
+ archetypeThemeDir := filepath.Join("themes", "mytheme", "archetypes", "my-theme-bundle")
+ assert.NoError(fs.Source.Mkdir(archetypeThemeDir, 0755))
+
contentFile := `
File: %s
Site Lang: {{ .Site.Language.Lang }}
@@ -107,6 +110,9 @@ i18n: {{ T "hugo" }}
assert.NoError(afero.WriteFile(fs.Source, filepath.Join(archetypeDir, "resources", "hugo1.json"), []byte(`hugo1: {{ printf "no template handling in here" }}`), 0755))
assert.NoError(afero.WriteFile(fs.Source, filepath.Join(archetypeDir, "resources", "hugo2.xml"), []byte(`hugo2: {{ printf "no template handling in here" }}`), 0755))
+ assert.NoError(afero.WriteFile(fs.Source, filepath.Join(archetypeThemeDir, "index.md"), []byte(fmt.Sprintf(contentFile, "index.md")), 0755))
+ assert.NoError(afero.WriteFile(fs.Source, filepath.Join(archetypeThemeDir, "resources", "hugo1.json"), []byte(`hugo1: {{ printf "no template handling in here" }}`), 0755))
+
h, err := hugolib.NewHugoSites(deps.DepsCfg{Cfg: cfg, Fs: fs})
assert.NoError(err)
assert.Equal(2, len(h.Sites))
@@ -123,6 +129,10 @@ i18n: {{ T "hugo" }}
assertContains(assert, readFileFromFs(t, fs.Source, filepath.Join("content", "post/my-post/pages/bio.md")), `File: bio.md`, `Site Lang: en`, `Name: My Post`)
+ assert.NoError(create.NewContent(h, "my-theme-bundle", "post/my-theme-post"))
+ assertContains(assert, readFileFromFs(t, fs.Source, filepath.Join("content", "post/my-theme-post/index.md")), `File: index.md`, `Site Lang: en`, `Name: My Theme Post`, `i18n: Hugo Rocks!`)
+ assertContains(assert, readFileFromFs(t, fs.Source, filepath.Join("content", "post/my-theme-post/resources/hugo1.json")), `hugo1: {{ printf "no template handling in here" }}`)
+
}
func initFs(fs *hugofs.Fs) error {
@@ -231,6 +241,8 @@ func readFileFromFs(t *testing.T, fs afero.Fs, filename string) string {
func newTestCfg(assert *require.Assertions) (*viper.Viper, *hugofs.Fs) {
cfg := `
+
+theme = "mytheme"
[languages]
[languages.en]