diff options
author | satotake <doublequotation@gmail.com> | 2022-09-01 00:23:31 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-09-08 15:35:11 +0200 |
commit | 7d40da876c62a166bdd273209b7cd6bead9266c1 (patch) | |
tree | f4a0aa6c7f45cbfc4181bcff8586db98a580be53 /hugolib | |
parent | 02c89a446d1a76491bfb4b9a756d892a83584d17 (diff) |
Add `--force` to `hugo new`
Closes #9243
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/content_factory.go | 5 | ||||
-rw-r--r-- | hugolib/content_factory_test.go | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/hugolib/content_factory.go b/hugolib/content_factory.go index 0a4d0aa0a..017a0bc97 100644 --- a/hugolib/content_factory.go +++ b/hugolib/content_factory.go @@ -110,7 +110,7 @@ func (f ContentFactory) SectionFromFilename(filename string) (string, error) { // CreateContentPlaceHolder creates a content placeholder file inside the // best matching content directory. -func (f ContentFactory) CreateContentPlaceHolder(filename string) (string, error) { +func (f ContentFactory) CreateContentPlaceHolder(filename string, force bool) (string, error) { filename = filepath.Clean(filename) _, abs, err := f.h.AbsProjectContentDir(filename) @@ -130,6 +130,9 @@ _build: ` + if force { + return abs, afero.WriteReader(f.h.Fs.Source, abs, strings.NewReader(placeholder)) + } return abs, afero.SafeWriteReader(f.h.Fs.Source, abs, strings.NewReader(placeholder)) } diff --git a/hugolib/content_factory_test.go b/hugolib/content_factory_test.go index 23dcd660a..2c4b843a9 100644 --- a/hugolib/content_factory_test.go +++ b/hugolib/content_factory_test.go @@ -43,7 +43,7 @@ Hello World. `) b.CreateSites() cf := NewContentFactory(b.H) - abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("mcontent/en/blog/mypage.md")) + abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("mcontent/en/blog/mypage.md"), false) b.Assert(err, qt.IsNil) b.Assert(abs, qt.Equals, filepath.FromSlash("/my/work/mcontent/en/blog/mypage.md")) b.Build(BuildCfg{SkipRender: true}) @@ -69,7 +69,7 @@ theme = 'ipsum' b.WithSourceFile(filepath.Join(themeDir, "content/posts/foo.txt"), `Hello.`) b.CreateSites() cf := NewContentFactory(b.H) - abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("posts/test.md")) + abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("posts/test.md"), false) b.Assert(err, qt.IsNil) b.Assert(abs, qt.Equals, filepath.FromSlash("content/posts/test.md")) |