Skip to content

Commit 5235a5b

Browse files
biodranikbep
authored andcommitted
Correct fix for --cleanDestinationDir flag
Fixes #4246 Fixes #4248
1 parent 1921a70 commit 5235a5b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

‎commands/hugo.go‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,36 @@ func (c *commandeer) fullBuild(watches ...bool) error {
561561
}()
562562
}
563563

564-
g.Go(func() error {
564+
copyStaticFunc := func() error {
565565
cnt, err := c.copyStatic()
566566
if err != nil {
567567
return fmt.Errorf("Error copying static files: %s", err)
568568
}
569569
langCount = cnt
570570
return nil
571-
})
572-
573-
g.Go(func() error {
571+
}
572+
buildSitesFunc := func() error {
574573
if err := c.buildSites(); err != nil {
575574
return fmt.Errorf("Error building site: %s", err)
576575
}
577-
578576
return nil
579-
})
580-
581-
if err := g.Wait(); err != nil {
582-
return err
577+
}
578+
// Do not copy static files and build sites in parallel if cleanDestinationDir is enabled.
579+
// This flag deletes all static resources in /public folder that are missing in /static,
580+
// and it does so at the end of copyStatic() call.
581+
if c.Cfg.GetBool("cleanDestinationDir") {
582+
if err := copyStaticFunc(); err != nil {
583+
return err
584+
}
585+
if err := buildSitesFunc(); err != nil {
586+
return err
587+
}
588+
} else {
589+
g.Go(copyStaticFunc)
590+
g.Go(buildSitesFunc)
591+
if err := g.Wait(); err != nil {
592+
return err
593+
}
583594
}
584595

585596
for _, s := range Hugo.Sites {

0 commit comments

Comments
 (0)