File tree Expand file tree Collapse file tree 3 files changed +46
-7
lines changed
Expand file tree Collapse file tree 3 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -751,6 +751,15 @@ func (s *IntegrationTestBuilder) AddFiles(filenameContent ...string) *Integratio
751751 return s
752752}
753753
754+ func (s * IntegrationTestBuilder ) CreateDirs (dirnames ... string ) * IntegrationTestBuilder {
755+ for _ , dirname := range dirnames {
756+ absDir := s .absFilename (filepath .FromSlash (dirname ))
757+ s .Assert (s .fs .Source .MkdirAll (absDir , 0o777 ), qt .IsNil )
758+ s .createdFiles = append (s .createdFiles , absDir )
759+ }
760+ return s
761+ }
762+
754763func (s * IntegrationTestBuilder ) RemoveFiles (filenames ... string ) * IntegrationTestBuilder {
755764 for _ , filename := range filenames {
756765 absFilename := s .absFilename (filename )
Original file line number Diff line number Diff line change @@ -399,6 +399,33 @@ func TestRebuilErrorRecovery(t *testing.T) {
399399 b .EditFileReplaceAll ("content/mysection/mysectionbundle/index.md" , "{{< foo }}" , "{{< foo >}}" ).Build ()
400400}
401401
402+ // Issue 14573
403+ func TestRebuildAddContentWithMultipleDirCreations (t * testing.T ) {
404+ t .Parallel ()
405+ files := `
406+ -- hugo.toml --
407+ baseURL = "https://example.com"
408+ disableLiveReload = true
409+ -- content/p1.md --
410+ ---
411+ title: "P1"
412+ ---
413+ -- layouts/page.html --
414+ Single: {{ .Title }}|{{ .Content }}|
415+ -- layouts/list.html --
416+ Pages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
417+ `
418+ b := TestRunning (t , files )
419+ b .AssertFileContent ("public/index.html" , "Pages: /p1/|$" )
420+ b .AddFiles (
421+ "content/nesteddir/dir1/post.md" , "---\n title: Post\n ---" ,
422+ ).CreateDirs (
423+ "content/dir1" ,
424+ "content/dir2" ,
425+ ).Build ()
426+ b .AssertFileContent ("public/nesteddir/dir1/post/index.html" , "Single: Post|" )
427+ }
428+
402429func TestRebuildAddPageListPagesInHome (t * testing.T ) {
403430 files := `
404431-- hugo.toml --
Original file line number Diff line number Diff line change @@ -1316,15 +1316,18 @@ func (h *HugoSites) fileEventsContentPaths(p []pathChange) []pathChange {
13161316 // Remove all files below dir.
13171317 if len (dirs ) > 0 {
13181318 n := 0
1319- for _ , d := range dirs {
1320- dir := d . p . Path () + "/"
1321- for _ , o := range others {
1322- if ! strings .HasPrefix (o .p .Path (), dir ) {
1323- others [ n ] = o
1324- n ++
1319+ for _ , o := range others {
1320+ keep := true
1321+ for _ , d := range dirs {
1322+ if strings .HasPrefix (o .p .Path (), d . p . Path () + "/" ) {
1323+ keep = false
1324+ break
13251325 }
13261326 }
1327-
1327+ if keep {
1328+ others [n ] = o
1329+ n ++
1330+ }
13281331 }
13291332 others = others [:n ]
13301333 }
You can’t perform that action at this time.
0 commit comments