diff options
Diffstat (limited to 'commands/static_syncer.go')
-rw-r--r-- | commands/static_syncer.go | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/commands/static_syncer.go b/commands/static_syncer.go index a04904f95..1e73e7fc2 100644 --- a/commands/static_syncer.go +++ b/commands/static_syncer.go @@ -17,53 +17,43 @@ import ( "os" "path/filepath" + "github.com/gohugoio/hugo/hugolib/filesystems" + "github.com/fsnotify/fsnotify" "github.com/gohugoio/hugo/helpers" - src "github.com/gohugoio/hugo/source" "github.com/spf13/fsync" ) type staticSyncer struct { c *commandeer - d *src.Dirs } func newStaticSyncer(c *commandeer) (*staticSyncer, error) { - dirs, err := src.NewDirs(c.Fs, c.Cfg, c.DepsCfg.Logger) - if err != nil { - return nil, err - } - - return &staticSyncer{c: c, d: dirs}, nil + return &staticSyncer{c: c}, nil } -func (s *staticSyncer) isStatic(path string) bool { - return s.d.IsStatic(path) +func (s *staticSyncer) isStatic(filename string) bool { + return s.c.hugo.BaseFs.SourceFilesystems.IsStatic(filename) } func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error { c := s.c - syncFn := func(dirs *src.Dirs, publishDir string) (uint64, error) { - staticSourceFs, err := dirs.CreateStaticFs() - if err != nil { - return 0, err - } - - if dirs.Language != nil { - // Multihost setup - publishDir = filepath.Join(publishDir, dirs.Language.Lang) + syncFn := func(sourceFs *filesystems.SourceFilesystem) (uint64, error) { + publishDir := c.hugo.PathSpec.PublishDir + // If root, remove the second '/' + if publishDir == "//" { + publishDir = helpers.FilePathSeparator } - if staticSourceFs == nil { - c.Logger.WARN.Println("No static directories found to sync") - return 0, nil + if sourceFs.PublishFolder != "" { + publishDir = filepath.Join(publishDir, sourceFs.PublishFolder) } syncer := fsync.NewSyncer() syncer.NoTimes = c.Cfg.GetBool("noTimes") syncer.NoChmod = c.Cfg.GetBool("noChmod") - syncer.SrcFs = staticSourceFs + syncer.SrcFs = sourceFs.Fs syncer.DestFs = c.Fs.Destination // prevent spamming the log on changes @@ -88,8 +78,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error { fromPath := ev.Name - // If we are here we already know the event took place in a static dir - relPath := dirs.MakeStaticPathRelative(fromPath) + relPath := sourceFs.MakePathRelative(fromPath) if relPath == "" { // Not member of this virtual host. continue @@ -105,7 +94,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error { // the source of that static file. In this case Hugo will incorrectly remove that file // from the published directory. if ev.Op&fsnotify.Rename == fsnotify.Rename || ev.Op&fsnotify.Remove == fsnotify.Remove { - if _, err := staticSourceFs.Stat(relPath); os.IsNotExist(err) { + if _, err := sourceFs.Fs.Stat(relPath); os.IsNotExist(err) { // If file doesn't exist in any static dir, remove it toRemove := filepath.Join(publishDir, relPath) |