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>2017-06-20 13:46:03 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-20 14:41:48 +0300
commit19f2e729135af700c5d4aa06e7b3540e6d4847fd (patch)
tree6f6b26222306c66b78bfa032de8d3e4bfce05f68 /create
parent0f40e1fadfca2276f65adefa6d7d5d63aef9160a (diff)
Support non-md files as archetype files
It now properly uses the extension of the target file to determine archetype file. Fixes #3597 Fixes #3618
Diffstat (limited to 'create')
-rw-r--r--create/content.go20
-rw-r--r--create/content_test.go5
2 files changed, 17 insertions, 8 deletions
diff --git a/create/content.go b/create/content.go
index e992b0836..e584df73e 100644
--- a/create/content.go
+++ b/create/content.go
@@ -30,10 +30,11 @@ import (
func NewContent(
ps *helpers.PathSpec,
siteFactory func(filename string, siteUsed bool) (*hugolib.Site, error), kind, targetPath string) error {
+ ext := helpers.Ext(targetPath)
- jww.INFO.Println("attempting to create ", targetPath, "of", kind)
+ jww.INFO.Printf("attempting to create %q of %q of ext %q", targetPath, kind, ext)
- archetypeFilename := findArchetype(ps, kind)
+ archetypeFilename := findArchetype(ps, kind, ext)
f, err := ps.Fs.Source.Open(archetypeFilename)
if err != nil {
@@ -84,7 +85,7 @@ func NewContent(
// FindArchetype takes a given kind/archetype of content and returns an output
// path for that archetype. If no archetype is found, an empty string is
// returned.
-func findArchetype(ps *helpers.PathSpec, kind string) (outpath string) {
+func findArchetype(ps *helpers.PathSpec, kind, ext string) (outpath string) {
search := []string{ps.AbsPathify(ps.Cfg.GetString("archetypeDir"))}
if ps.Cfg.GetString("theme") != "" {
@@ -100,13 +101,16 @@ func findArchetype(ps *helpers.PathSpec, kind string) (outpath string) {
// If the new content isn't in a subdirectory, kind == "".
// Therefore it should be excluded otherwise `is a directory`
// error will occur. github.com/gohugoio/hugo/issues/411
- var pathsToCheck []string
+ var pathsToCheck = []string{"default"}
- if kind == "" {
- pathsToCheck = []string{"default.md", "default"}
- } else {
- pathsToCheck = []string{kind + ".md", kind, "default.md", "default"}
+ if ext != "" {
+ if kind != "" {
+ pathsToCheck = append([]string{kind + ext, "default" + ext}, pathsToCheck...)
+ } else {
+ pathsToCheck = append([]string{"default" + ext}, pathsToCheck...)
+ }
}
+
for _, p := range pathsToCheck {
curpath := filepath.Join(x, p)
jww.DEBUG.Println("checking", curpath, "for archetypes")
diff --git a/create/content_test.go b/create/content_test.go
index 8b6c2c12c..e8857baf2 100644
--- a/create/content_test.go
+++ b/create/content_test.go
@@ -44,6 +44,7 @@ func TestNewContent(t *testing.T) {
expected []string
}{
{"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
@@ -112,6 +113,10 @@ func initFs(fs *hugofs.Fs) error {
content: "+++\ndate = \"2015-01-12T19:20:04-07:00\"\ntitle = \"Post Arch title\"\ntest = \"test1\"\n+++\n",
},
{
+ path: filepath.Join("archetypes", "post.org"),
+ content: "#+title: {{ .BaseFileName | upper }}",
+ },
+ {
path: filepath.Join("archetypes", "product.md"),
content: `+++
title = "{{ .BaseFileName | upper }}"