return s
}
+func (s *IntegrationTestBuilder) CreateDirs(dirnames ...string) *IntegrationTestBuilder {
+ for _, dirname := range dirnames {
+ absDir := s.absFilename(filepath.FromSlash(dirname))
+ s.Assert(s.fs.Source.MkdirAll(absDir, 0o777), qt.IsNil)
+ s.createdFiles = append(s.createdFiles, absDir)
+ }
+ return s
+}
+
func (s *IntegrationTestBuilder) RemoveFiles(filenames ...string) *IntegrationTestBuilder {
for _, filename := range filenames {
absFilename := s.absFilename(filename)
b.EditFileReplaceAll("content/mysection/mysectionbundle/index.md", "{{< foo }}", "{{< foo >}}").Build()
}
+// Issue 14573
+func TestRebuildAddContentWithMultipleDirCreations(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableLiveReload = true
+-- content/p1.md --
+---
+title: "P1"
+---
+-- layouts/page.html --
+Single: {{ .Title }}|{{ .Content }}|
+-- layouts/list.html --
+Pages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
+`
+ b := TestRunning(t, files)
+ b.AssertFileContent("public/index.html", "Pages: /p1/|$")
+ b.AddFiles(
+ "content/nesteddir/dir1/post.md", "---\ntitle: Post\n---",
+ ).CreateDirs(
+ "content/dir1",
+ "content/dir2",
+ ).Build()
+ b.AssertFileContent("public/nesteddir/dir1/post/index.html", "Single: Post|")
+}
+
func TestRebuildAddPageListPagesInHome(t *testing.T) {
files := `
-- hugo.toml --
// Remove all files below dir.
if len(dirs) > 0 {
n := 0
- for _, d := range dirs {
- dir := d.p.Path() + "/"
- for _, o := range others {
- if !strings.HasPrefix(o.p.Path(), dir) {
- others[n] = o
- n++
+ for _, o := range others {
+ keep := true
+ for _, d := range dirs {
+ if strings.HasPrefix(o.p.Path(), d.p.Path()+"/") {
+ keep = false
+ break
}
}
-
+ if keep {
+ others[n] = o
+ n++
+ }
}
others = others[:n]
}