mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
committed by
Bjørn Erik Pedersen
parent
02c89a446d
commit
7d40da876c
@@ -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))
|
||||
}
|
||||
|
||||
|
@@ -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"))
|
||||
|
||||
|
Reference in New Issue
Block a user