summaryrefslogtreecommitdiffstats
path: root/create
diff options
context:
space:
mode:
Diffstat (limited to 'create')
-rw-r--r--create/content.go17
-rw-r--r--create/content_template_handler.go7
-rw-r--r--create/content_test.go2
3 files changed, 23 insertions, 3 deletions
diff --git a/create/content.go b/create/content.go
index 8af417294..29fe47394 100644
--- a/create/content.go
+++ b/create/content.go
@@ -63,7 +63,22 @@ func NewContent(
return err
}
- contentPath := s.PathSpec.AbsPathify(filepath.Join(s.Cfg.GetString("contentDir"), targetPath))
+ // The site may have multiple content dirs, and we currently do not know which contentDir the
+ // user wants to create this content in. We should improve on this, but we start by testing if the
+ // provided path points to an existing dir. If so, use it as is.
+ var contentPath string
+ var exists bool
+ targetDir := filepath.Dir(targetPath)
+
+ if targetDir != "" && targetDir != "." {
+ exists, _ = helpers.Exists(targetDir, ps.Fs.Source)
+ }
+
+ if exists {
+ contentPath = targetPath
+ } else {
+ contentPath = s.PathSpec.AbsPathify(filepath.Join(s.Cfg.GetString("contentDir"), targetPath))
+ }
if err := helpers.SafeWriteToDisk(contentPath, bytes.NewReader(content), s.Fs.Source); err != nil {
return err
diff --git a/create/content_template_handler.go b/create/content_template_handler.go
index 705efbd20..e9e7cb62b 100644
--- a/create/content_template_handler.go
+++ b/create/content_template_handler.go
@@ -88,10 +88,15 @@ func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFile
err error
)
- sp := source.NewSourceSpec(s.Deps.Cfg, s.Deps.Fs)
+ ps, err := helpers.NewPathSpec(s.Deps.Fs, s.Deps.Cfg)
+ sp := source.NewSourceSpec(ps, ps.Fs.Source)
+ if err != nil {
+ return nil, err
+ }
f := sp.NewFileInfo("", targetPath, false, nil)
name := f.TranslationBaseName()
+
if name == "index" || name == "_index" {
// Page bundles; the directory name will hopefully have a better name.
dir := strings.TrimSuffix(f.Dir(), helpers.FilePathSeparator)
diff --git a/create/content_test.go b/create/content_test.go
index 914759164..62d5ed1da 100644
--- a/create/content_test.go
+++ b/create/content_test.go
@@ -75,7 +75,7 @@ func TestNewContent(t *testing.T) {
for i, v := range c.expected {
found := strings.Contains(content, v)
if !found {
- t.Errorf("[%d] %q missing from output:\n%q", i, v, content)
+ t.Fatalf("[%d] %q missing from output:\n%q", i, v, content)
}
}
}