summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/benchmark.go2
-rw-r--r--commands/commandeer.go52
-rw-r--r--commands/commands.go2
-rw-r--r--commands/commands_test.go5
-rw-r--r--commands/config.go2
-rw-r--r--commands/convert.go2
-rw-r--r--commands/hugo.go205
-rw-r--r--commands/list.go6
-rw-r--r--commands/new.go5
-rw-r--r--commands/new_theme.go6
-rw-r--r--commands/server.go4
-rw-r--r--commands/static_syncer.go41
12 files changed, 120 insertions, 212 deletions
diff --git a/commands/benchmark.go b/commands/benchmark.go
index 3938acf1b..b0a12db7f 100644
--- a/commands/benchmark.go
+++ b/commands/benchmark.go
@@ -56,7 +56,7 @@ func (c *benchmarkCmd) benchmark(cmd *cobra.Command, args []string) error {
return nil
}
- comm, err := initializeConfig(false, &c.hugoBuilderCommon, c, cfgInit)
+ comm, err := initializeConfig(true, false, &c.hugoBuilderCommon, c, cfgInit)
if err != nil {
return err
}
diff --git a/commands/commandeer.go b/commands/commandeer.go
index d43b7c9f1..d5d2740bf 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -34,7 +34,7 @@ import (
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
- src "github.com/gohugoio/hugo/source"
+ "github.com/gohugoio/hugo/langs"
)
type commandeer struct {
@@ -45,11 +45,8 @@ type commandeer struct {
h *hugoBuilderCommon
ftch flagsToConfigHandler
- pathSpec *helpers.PathSpec
visitedURLs *types.EvictingStringQueue
- staticDirsConfig []*src.Dirs
-
// We watch these for changes.
configFiles []string
@@ -63,7 +60,7 @@ type commandeer struct {
serverPorts []int
languagesConfigured bool
- languages helpers.Languages
+ languages langs.Languages
configured bool
}
@@ -75,31 +72,13 @@ func (c *commandeer) Set(key string, value interface{}) {
c.Cfg.Set(key, value)
}
-// PathSpec lazily creates a new PathSpec, as all the paths must
-// be configured before it is created.
-func (c *commandeer) PathSpec() *helpers.PathSpec {
- c.configured = true
- return c.pathSpec
-}
-
func (c *commandeer) initFs(fs *hugofs.Fs) error {
c.DepsCfg.Fs = fs
- ps, err := helpers.NewPathSpec(fs, c.Cfg)
- if err != nil {
- return err
- }
- c.pathSpec = ps
-
- dirsConfig, err := c.createStaticDirsConfig()
- if err != nil {
- return err
- }
- c.staticDirsConfig = dirsConfig
return nil
}
-func newCommandeer(running bool, h *hugoBuilderCommon, f flagsToConfigHandler, doWithCommandeer func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
+func newCommandeer(mustHaveConfigFile, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, doWithCommandeer func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
var rebuildDebouncer func(f func())
if running {
@@ -117,10 +96,10 @@ func newCommandeer(running bool, h *hugoBuilderCommon, f flagsToConfigHandler, d
debounce: rebuildDebouncer,
}
- return c, c.loadConfig(running)
+ return c, c.loadConfig(mustHaveConfigFile, running)
}
-func (c *commandeer) loadConfig(running bool) error {
+func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
if c.DepsCfg == nil {
c.DepsCfg = &deps.DepsCfg{}
@@ -168,12 +147,18 @@ func (c *commandeer) loadConfig(running bool) error {
doWithConfig)
if err != nil {
- return err
+ if mustHaveConfigFile {
+ return err
+ }
+ if err != hugolib.ErrNoConfigFile {
+ return err
+ }
+
}
c.configFiles = configFiles
- if l, ok := c.Cfg.Get("languagesSorted").(helpers.Languages); ok {
+ if l, ok := c.Cfg.Get("languagesSorted").(langs.Languages); ok {
c.languagesConfigured = true
c.languages = l
}
@@ -209,6 +194,15 @@ func (c *commandeer) loadConfig(running bool) error {
}
err = c.initFs(fs)
+ if err != nil {
+ return
+ }
+
+ var h *hugolib.HugoSites
+
+ h, err = hugolib.NewHugoSites(*c.DepsCfg)
+ c.hugo = h
+
})
if err != nil {
@@ -232,7 +226,7 @@ func (c *commandeer) loadConfig(running bool) error {
cfg.Logger.INFO.Println("Using config file:", config.ConfigFileUsed())
- themeDir := c.PathSpec().GetThemeDir()
+ themeDir := c.hugo.PathSpec.GetFirstThemeDir()
if themeDir != "" {
if _, err := sourceFs.Stat(themeDir); os.IsNotExist(err) {
return newSystemError("Unable to find theme Directory:", themeDir)
diff --git a/commands/commands.go b/commands/commands.go
index 8ba28e10d..74bc709cc 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -148,7 +148,7 @@ Complete documentation is available at http://gohugo.io/.`,
return nil
}
- c, err := initializeConfig(cc.buildWatch, &cc.hugoBuilderCommon, cc, cfgInit)
+ c, err := initializeConfig(true, cc.buildWatch, &cc.hugoBuilderCommon, cc, cfgInit)
if err != nil {
return err
}
diff --git a/commands/commands_test.go b/commands/commands_test.go
index 907f003c0..d576b4428 100644
--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -237,6 +237,11 @@ List: {{ .Title }}
`)
+ writeFile(t, filepath.Join(d, "static", "my.txt"), `
+MyMy
+
+`)
+
return d, nil
}
diff --git a/commands/config.go b/commands/config.go
index 951b57540..33a61733d 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -44,7 +44,7 @@ func newConfigCmd() *configCmd {
}
func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
- cfg, err := initializeConfig(false, &c.hugoBuilderCommon, c, nil)
+ cfg, err := initializeConfig(true, false, &c.hugoBuilderCommon, c, nil)
if err != nil {
return err
diff --git a/commands/convert.go b/commands/convert.go
index fb70a148d..8de155e9b 100644
--- a/commands/convert.go
+++ b/commands/convert.go
@@ -96,7 +96,7 @@ func (cc *convertCmd) convertContents(mark rune) error {
return newUserError("Unsafe operation not allowed, use --unsafe or set a different output path")
}
- c, err := initializeConfig(false, &cc.hugoBuilderCommon, cc, nil)
+ c, err := initializeConfig(true, false, &cc.hugoBuilderCommon, cc, nil)
if err != nil {
return err
}
diff --git a/commands/hugo.go b/commands/hugo.go
index 8f7860f76..c4fee122d 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -23,6 +23,8 @@ import (
"sync/atomic"
"syscall"
+ "github.com/gohugoio/hugo/hugolib/filesystems"
+
"golang.org/x/sync/errgroup"
"log"
@@ -32,8 +34,6 @@ import (
"strings"
"time"
- src "github.com/gohugoio/hugo/source"
-
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/parser"
@@ -103,12 +103,12 @@ func Execute(args []string) Response {
}
// InitializeConfig initializes a config file with sensible default configuration flags.
-func initializeConfig(running bool,
+func initializeConfig(mustHaveConfigFile, running bool,
h *hugoBuilderCommon,
f flagsToConfigHandler,
doWithCommandeer func(c *commandeer) error) (*commandeer, error) {
- c, err := newCommandeer(running, h, f, doWithCommandeer)
+ c, err := newCommandeer(mustHaveConfigFile, running, h, f, doWithCommandeer)
if err != nil {
return nil, err
}
@@ -280,6 +280,7 @@ func (c *commandeer) fullBuild() error {
return fmt.Errorf("Error copying static files: %s", err)
}
langCount = cnt
+ langCount = cnt
return nil
}
buildSitesFunc := func() error {
@@ -344,7 +345,7 @@ func (c *commandeer) build() error {
if err != nil {
return err
}
- c.Logger.FEEDBACK.Println("Watching for changes in", c.PathSpec().AbsPathify(c.Cfg.GetString("contentDir")))
+ c.Logger.FEEDBACK.Println("Watching for changes in", c.hugo.PathSpec.AbsPathify(c.Cfg.GetString("contentDir")))
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
watcher, err := c.newWatcher(watchDirs...)
utils.CheckErr(c.Logger, err)
@@ -380,49 +381,30 @@ func (c *commandeer) copyStatic() (map[string]uint64, error) {
return c.doWithPublishDirs(c.copyStaticTo)
}
-func (c *commandeer) createStaticDirsConfig() ([]*src.Dirs, error) {
- var dirsConfig []*src.Dirs
-
- if !c.languages.IsMultihost() {
- dirs, err := src.NewDirs(c.Fs, c.Cfg, c.DepsCfg.Logger)
- if err != nil {
- return nil, err
- }
- dirsConfig = append(dirsConfig, dirs)
- } else {
- for _, l := range c.languages {
- dirs, err := src.NewDirs(c.Fs, l, c.DepsCfg.Logger)
- if err != nil {
- return nil, err
- }
- dirsConfig = append(dirsConfig, dirs)
- }
- }
-
- return dirsConfig, nil
-
-}
-
-func (c *commandeer) doWithPublishDirs(f func(dirs *src.Dirs, publishDir string) (uint64, error)) (map[string]uint64, error) {
+func (c *commandeer) doWithPublishDirs(f func(sourceFs *filesystems.SourceFilesystem) (uint64, error)) (map[string]uint64, error) {
langCount := make(map[string]uint64)
- for _, dirs := range c.staticDirsConfig {
+ staticFilesystems := c.hugo.BaseFs.SourceFilesystems.Static
- cnt, err := f(dirs, c.pathSpec.PublishDir)
+ if len(staticFilesystems) == 0 {
+ c.Logger.WARN.Println("No static directories found to sync")
+ return langCount, nil
+ }
+
+ for lang, fs := range staticFilesystems {
+ cnt, err := f(fs)
if err != nil {
return langCount, err
}
-
- if dirs.Language == nil {
+ if lang == "" {
// Not multihost
for _, l := range c.languages {
langCount[l.Lang] = cnt
}
} else {
- langCount[dirs.Language.Lang] = cnt
+ langCount[lang] = cnt
}
-
}
return langCount, nil
@@ -443,29 +425,18 @@ func (fs *countingStatFs) Stat(name string) (os.FileInfo, error) {
return f, err
}
-func (c *commandeer) copyStaticTo(dirs *src.Dirs, publishDir string) (uint64, error) {
-
+func (c *commandeer) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint64, error) {
+ publishDir := c.hugo.PathSpec.PublishDir
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
- if dirs.Language != nil {
- // Multihost setup.
- publishDir = filepath.Join(publishDir, dirs.Language.Lang)
+ if sourceFs.PublishFolder != "" {
+ publishDir = filepath.Join(publishDir, sourceFs.PublishFolder)
}
- staticSourceFs, err := dirs.CreateStaticFs()
- if err != nil {
- return 0, err
- }
-
- if staticSourceFs == nil {
- c.Logger.WARN.Println("No static directories found to sync")
- return 0, nil
- }
-
- fs := &countingStatFs{Fs: staticSourceFs}
+ fs := &countingStatFs{Fs: sourceFs.Fs}
syncer := fsync.NewSyncer()
syncer.NoTimes = c.Cfg.GetBool("noTimes")
@@ -485,6 +456,8 @@ func (c *commandeer) copyStaticTo(dirs *src.Dirs, publishDir string) (uint64, er
}
c.Logger.INFO.Println("syncing static files to", publishDir)
+ var err error
+
// because we are using a baseFs (to get the union right).
// set sync src to root
err = syncer.Sync(publishDir, helpers.FilePathSeparator)
@@ -514,41 +487,10 @@ func (c *commandeer) getDirList() ([]string, error) {
var seen = make(map[string]bool)
var nested []string
- dataDir := c.PathSpec().AbsPathify(c.Cfg.GetString("dataDir"))
- i18nDir := c.PathSpec().AbsPathify(c.Cfg.GetString("i18nDir"))
- staticSyncer, err := newStaticSyncer(c)
- if err != nil {
- return nil, err
- }
-
- layoutDir := c.PathSpec().GetLayoutDirPath()
- staticDirs := staticSyncer.d.AbsStaticDirs
-
newWalker := func(allowSymbolicDirs bool) func(path string, fi os.FileInfo, err error) error {
return func(path string, fi os.FileInfo, err error) error {
if err != nil {
- if path == dataDir && os.IsNotExist(err) {
- c.Logger.WARN.Println("Skip dataDir:", err)
- return nil
- }
-
- if path == i18nDir && os.IsNotExist(err) {
- c.Logger.WARN.Println("Skip i18nDir:", err)
- return nil
- }
-
- if path == layoutDir && os.IsNotExist(err) {
- c.Logger.WARN.Println("Skip layoutDir:", err)
- return nil
- }
-
if os.IsNotExist(err) {
- for _, staticDir := range staticDirs {
- if path == staticDir && os.IsNotExist(err) {
- c.Logger.WARN.Println("Skip staticDir:", err)
- }
- }
- // Ignore.
return nil
}
@@ -605,23 +547,28 @@ func (c *commandeer) getDirList() ([]string, error) {
regularWalker := newWalker(false)
// SymbolicWalk will log anny ERRORs
- _ = helpers.SymbolicWalk(c.Fs.Source, dataDir, regularWalker)
- _ = helpers.SymbolicWalk(c.Fs.Source, i18nDir, regularWalker)
- _ = helpers.SymbolicWalk(c.Fs.Source, layoutDir, regularWalker)
-
- for _, contentDir := range c.PathSpec().ContentDirs() {
+ // Also note that the Dirnames fetched below will contain any relevant theme
+ // directories.
+ for _, contentDir := range c.hugo.PathSpec.BaseFs.AbsContentDirs {
_ = helpers.SymbolicWalk(c.Fs.Source, contentDir.Value, symLinkWalker)
}
- for _, staticDir := range staticDirs {
+ for _, staticDir := range c.hugo.PathSpec.BaseFs.Data.Dirnames {
_ = helpers.SymbolicWalk(c.Fs.Source, staticDir, regularWalker)
}
- if c.PathSpec().ThemeSet() {
- themesDir := c.PathSpec().GetThemeDir()
- _ = helpers.SymbolicWalk(c.Fs.Source, filepath.Join(themesDir, "layouts"), regularWalker)
- _ = helpers.SymbolicWalk(c.Fs.Source, filepath.Join(themesDir, "i18n"), regularWalker)
- _ = helpers.SymbolicWalk(c.Fs.Source, filepath.Join(themesDir, "data"), regularWalker)
+ for _, staticDir := range c.hugo.PathSpec.BaseFs.I18n.Dirnames {
+ _ = helpers.SymbolicWalk(c.Fs.Source, staticDir, regularWalker)
+ }
+
+ for _, staticDir := range c.hugo.PathSpec.BaseFs.Layouts.Dirnames {
+ _ = helpers.SymbolicWalk(c.Fs.Source, staticDir, regularWalker)
+ }
+
+ for _, staticFilesystem := range c.hugo.PathSpec.BaseFs.Static {
+ for _, staticDir := range staticFilesystem.Dirnames {
+ _ = helpers.SymbolicWalk(c.Fs.Source, staticDir, regularWalker)
+ }
}
if len(nested) > 0 {
@@ -648,9 +595,6 @@ func (c *commandeer) getDirList() ([]string, error) {
func (c *commandeer) recreateAndBuildSites(watching bool) (err error) {
defer c.timeTrack(time.Now(), "Total")
- if err := c.initSites(); err != nil {
- return err
- }
if !c.h.quiet {
c.Logger.FEEDBACK.Println("Started building sites ...")
}
@@ -658,56 +602,30 @@ func (c *commandeer) recreateAndBuildSites(watching bool) (err error) {
}
func (c *commandeer) resetAndBuildSites() (err error) {
- if err = c.initSites(); err != nil {
- return
- }
if !c.h.quiet {
c.Logger.FEEDBACK.Println("Started building sites ...")
}
return c.hugo.Build(hugolib.BuildCfg{ResetState: true})
}
-func (c *commandeer) initSites() error {
- if c.hugo != nil {
- c.hugo.Cfg = c.Cfg
- return nil
- }
-
- h, err := hugolib.NewHugoSites(*c.DepsCfg)
-
- if err != nil {
- return err
- }
-
- c.hugo = h
-
- return nil
-}
-
func (c *commandeer) buildSites() (err error) {
- if err := c.initSites(); err != nil {
- return err
- }
return c.hugo.Build(hugolib.BuildCfg{})
}
func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
defer c.timeTrack(time.Now(), "Total")
- if err := c.initSites(); err != nil {
- return err
- }
visited := c.visitedURLs.PeekAllSet()
doLiveReload := !c.h.buildWatch && !c.Cfg.GetBool("disableLiveReload")
if doLiveReload && !c.Cfg.GetBool("disableFastRender") {
// Make sure we always render the home pages
for _, l := range c.languages {
- langPath := c.PathSpec().GetLangSubDir(l.Lang)
+ langPath := c.hugo.PathSpec.GetLangSubDir(l.Lang)
if langPath != "" {
langPath = langPath + "/"
}
- home := c.pathSpec.PrependBasePath("/" + langPath)
+ home := c.hugo.PathSpec.PrependBasePath("/" + langPath)
visited[home] = true
}
@@ -716,7 +634,7 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
}
func (c *commandeer) fullRebuild() {
- if err := c.loadConfig(true); err != nil {
+ if err := c.loadConfig(true, true); err != nil {
jww.ERROR.Println("Failed to reload config:", err)
} else if err := c.recreateAndBuildSites(true); err != nil {
jww.ERROR.Println(err)
@@ -906,7 +824,8 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
// force refresh when more than one file
if len(staticEvents) > 0 {
for _, ev := range staticEvents {
- path := staticSyncer.d.MakeStaticPathRelative(ev.Name)
+
+ path := c.hugo.BaseFs.SourceFilesystems.MakeStaticPathRelative(ev.Name)
livereload.RefreshPath(path)
}
@@ -975,32 +894,36 @@ func pickOneWriteOrCreatePath(events []fsnotify.Event) string {
}
// isThemeVsHugoVersionMismatch returns whether the current Hugo version is
-// less than the theme's min_version.
+// less than any of the themes' min_version.
func (c *commandeer) isThemeVsHugoVersionMismatch(fs afero.Fs) (mismatch bool, requiredMinVersion string) {
- if !c.PathSpec().ThemeSet() {
+ if !c.hugo.PathSpec.ThemeSet() {
return
}
- themeDir := c.PathSpec().GetThemeDir()
+ for _, absThemeDir := range c.hugo.BaseFs.AbsThemeDirs {
- path := filepath.Join(themeDir, "theme.toml")
+ path := filepath.Join(absThemeDir, "theme.toml")
- exists, err := helpers.Exists(path, fs)
+ exists, err := helpers.Exists(path, fs)
- if err != nil || !exists {
- return
- }
+ if err != nil || !exists {
+ continue
+ }
- b, err := afero.ReadFile(fs, path)
+ b, err := afero.ReadFile(fs, path)
- tomlMeta, err := parser.HandleTOMLMetaData(b)
+ tomlMeta, err := parser.HandleTOMLMetaData(b)
- if err != nil {
- return
- }
+ if err != nil {
+ continue
+ }
+
+ if minVersion, ok := tomlMeta["min_version"]; ok {
+ if helpers.CompareVersion(minVersion) > 0 {
+ return true, fmt.Sprint(minVersion)
+ }
+ }
- if minVersion, ok := tomlMeta["min_version"]; ok {
- return helpers.CompareVersion(minVersion) > 0, fmt.Sprint(minVersion)
}
return
diff --git a/commands/list.go b/commands/list.go
index 57a92082c..9922e957d 100644
--- a/commands/list.go
+++ b/commands/list.go
@@ -50,7 +50,7 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.",
c.Set("buildDrafts", true)
return nil
}
- c, err := initializeConfig(false, &cc.hugoBuilderCommon, cc, cfgInit)
+ c, err := initializeConfig(true, false, &cc.hugoBuilderCommon, cc, cfgInit)
if err != nil {
return err
}
@@ -86,7 +86,7 @@ posted in the future.`,
c.Set("buildFuture", true)
return nil
}
- c, err := initializeConfig(false, &cc.hugoBuilderCommon, cc, cfgInit)
+ c, err := initializeConfig(true, false, &cc.hugoBuilderCommon, cc, cfgInit)
if err != nil {
return err
}
@@ -122,7 +122,7 @@ expired.`,
c.Set("buildExpired", true)
return nil
}
- c, err := initializeConfig(false, &cc.hugoBuilderCommon, cc, cfgInit)
+ c, err := initializeConfig(true, false, &cc.hugoBuilderCommon, cc, cfgInit)
if err != nil {
return err
}
diff --git a/commands/new.go b/commands/new.go
index c088dca9b..27d079b0d 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -71,7 +71,7 @@ func (n *newCmd) newContent(cmd *cobra.Command, args []string) error {
return nil
}
- c, err := initializeConfig(false, &n.hugoBuilderCommon, n, cfgInit)
+ c, err := initializeConfig(true, false, &n.hugoBuilderCommon, n, cfgInit)
if err != nil {
return err
@@ -104,9 +104,6 @@ func (n *newCmd) newContent(cmd *cobra.Command, args []string) error {
return hugolib.NewSite(*cfg)
}
var s *hugolib.Site
- if err := c.initSites(); err != nil {
- return nil, err
- }
if err := c.hugo.Build(hugolib.BuildCfg{SkipRender: true}); err != nil {
return nil, err
diff --git a/commands/new_theme.go b/commands/new_theme.go
index 3b00cb1df..9464e1968 100644
--- a/commands/new_theme.go
+++ b/commands/new_theme.go
@@ -54,7 +54,7 @@ as you see fit.`,
}
func (n *newThemeCmd) newTheme(cmd *cobra.Command, args []string) error {
- c, err := initializeConfig(false, &n.hugoBuilderCommon, n, nil)
+ c, err := initializeConfig(false, false, &n.hugoBuilderCommon, n, nil)
if err != nil {
return err
@@ -64,7 +64,7 @@ func (n *newThemeCmd) newTheme(cmd *cobra.Command, args []string) error {
return newUserError("theme name needs to be provided")
}
- createpath := c.PathSpec().AbsPathify(filepath.Join(c.Cfg.GetString("themesDir"), args[0]))
+ createpath := c.hugo.PathSpec.AbsPathify(filepath.Join(c.Cfg.GetString("themesDir"), args[0]))
jww.INFO.Println("creating theme at", createpath)
cfg := c.DepsCfg
@@ -140,7 +140,7 @@ description = ""
homepage = "http://example.com/"
tags = []
features = []
-min_version = "0.38"
+min_version = "0.41"
[author]
name = ""
diff --git a/commands/server.go b/commands/server.go
index c05180de9..8089b0ade 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -226,7 +226,7 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
jww.ERROR.Println("memstats error:", err)
}
- c, err := initializeConfig(true, &s.hugoBuilderCommon, s, cfgInit)
+ c, err := initializeConfig(true, true, &s.hugoBuilderCommon, s, cfgInit)
if err != nil {
return err
}
@@ -288,7 +288,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro
publishDir = filepath.Join(publishDir, root)
}
- absPublishDir := f.c.PathSpec().AbsPathify(publishDir)
+ absPublishDir := f.c.hugo.PathSpec.AbsPathify(publishDir)
if i == 0 {
if f.s.renderToDisk {
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)