Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/create
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-11-12 12:29:13 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-11-12 14:05:31 +0300
commit5f3f60898cfe1c087841ec1fbd5ddc2916d0a2c6 (patch)
treeda8e1bdc14a8086cf4075b30b279dba47cea8961 /create
parent057d02de256a3866b7044abaa4d03c69d9fedef0 (diff)
create: Improve archetype directory discovery and tests
Updates #9146
Diffstat (limited to 'create')
-rw-r--r--create/content.go3
-rw-r--r--create/content_test.go17
2 files changed, 18 insertions, 2 deletions
diff --git a/create/content.go b/create/content.go
index 52393ce5b..524803d36 100644
--- a/create/content.go
+++ b/create/content.go
@@ -252,7 +252,8 @@ func (b *contentBuilder) setArcheTypeFilenameToUse(ext string) {
if b.kind != "" {
pathsToCheck = append(pathsToCheck, b.kind+ext)
}
- pathsToCheck = append(pathsToCheck, "default"+ext, "default")
+
+ pathsToCheck = append(pathsToCheck, "default"+ext)
for _, p := range pathsToCheck {
fi, err := b.archeTypeFs.Stat(p)
diff --git a/create/content_test.go b/create/content_test.go
index 2d68f7610..a3692251f 100644
--- a/create/content_test.go
+++ b/create/content_test.go
@@ -167,7 +167,9 @@ func TestNewContentFromDirSiteFunction(t *testing.T) {
c := qt.New(t)
archetypeDir := filepath.Join("archetypes", "my-bundle")
+ defaultArchetypeDir := filepath.Join("archetypes", "default")
c.Assert(mm.MkdirAll(archetypeDir, 0o755), qt.IsNil)
+ c.Assert(mm.MkdirAll(defaultArchetypeDir, 0o755), qt.IsNil)
contentFile := `
File: %s
@@ -176,6 +178,7 @@ site RegularPages: {{ len site.RegularPages }}
`
c.Assert(afero.WriteFile(mm, filepath.Join(archetypeDir, "index.md"), []byte(fmt.Sprintf(contentFile, "index.md")), 0o755), qt.IsNil)
+ c.Assert(afero.WriteFile(mm, filepath.Join(defaultArchetypeDir, "index.md"), []byte("default archetype index.md"), 0o755), qt.IsNil)
c.Assert(initFs(mm), qt.IsNil)
cfg, fs := newTestCfg(c, mm)
@@ -185,8 +188,20 @@ site RegularPages: {{ len site.RegularPages }}
c.Assert(len(h.Sites), qt.Equals, 2)
c.Assert(create.NewContent(h, "my-bundle", "post/my-post"), qt.IsNil)
-
cContains(c, readFileFromFs(t, fs.Source, filepath.Join("content", "post/my-post/index.md")), `site RegularPages: 10`)
+
+ // Default bundle archetype
+ c.Assert(create.NewContent(h, "", "post/my-post2"), qt.IsNil)
+ cContains(c, readFileFromFs(t, fs.Source, filepath.Join("content", "post/my-post2/index.md")), `default archetype index.md`)
+
+ // Regular file with bundle kind.
+ c.Assert(create.NewContent(h, "my-bundle", "post/foo.md"), qt.IsNil)
+ cContains(c, readFileFromFs(t, fs.Source, filepath.Join("content", "post/foo.md")), `draft: true`)
+
+ // Regular files should fall back to the default archetype (we have no regular file archetype).
+ c.Assert(create.NewContent(h, "my-bundle", "mypage.md"), qt.IsNil)
+ cContains(c, readFileFromFs(t, fs.Source, filepath.Join("content", "mypage.md")), `draft: true`)
+
}
func TestNewContentFromDirNoSite(t *testing.T) {