diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-11-15 10:25:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-11-15 11:21:39 +0100 |
commit | b8155452ac699473b6b2a34f53988dee01b4da34 (patch) | |
tree | 07f88f6bdac3f09d009dc818ab9a2b95facb03aa /hugolib/filesystems | |
parent | 08552a7a4cd1fe64efdd2f1b95142fa4295cb298 (diff) | |
download | hugo-b8155452ac699473b6b2a34f53988dee01b4da34.tar.gz hugo-b8155452ac699473b6b2a34f53988dee01b4da34.zip |
Improve error when we cannot determine content directory in "hugo new"
See #9166
Diffstat (limited to 'hugolib/filesystems')
-rw-r--r-- | hugolib/filesystems/basefs.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 939d88459..be765ef9d 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -132,7 +132,7 @@ func (b *BaseFs) RelContentDir(filename string) string { // AbsProjectContentDir tries to construct a filename below the most // relevant content directory. -func (b *BaseFs) AbsProjectContentDir(filename string) (string, string) { +func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) { isAbs := filepath.IsAbs(filename) for _, dir := range b.SourceFilesystems.Content.Dirs { meta := dir.Meta() @@ -141,14 +141,14 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string) { } if isAbs { if strings.HasPrefix(filename, meta.Filename) { - return strings.TrimPrefix(filename, meta.Filename), filename + return strings.TrimPrefix(filename, meta.Filename), filename, nil } } else { contentDir := strings.TrimPrefix(strings.TrimPrefix(meta.Filename, meta.BaseDir), filePathSeparator) if strings.HasPrefix(filename, contentDir) { relFilename := strings.TrimPrefix(filename, contentDir) absFilename := filepath.Join(meta.Filename, relFilename) - return relFilename, absFilename + return relFilename, absFilename, nil } } @@ -162,12 +162,12 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string) { for i := len(contentDirs) - 1; i >= 0; i-- { meta := contentDirs[i].Meta() if meta.Module == "project" { - return filename, filepath.Join(meta.Filename, filename) + return filename, filepath.Join(meta.Filename, filename), nil } } } - return "", "" + return "", "", errors.Errorf("could not determine content directory for %q", filename) } // ResolveJSConfigFile resolves the JS-related config file to a absolute |