aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-06-08 11:52:22 +0200
committerBjørn Erik Pedersen <[email protected]>2024-06-23 11:25:47 +0200
commit6cd0784e447f18e009cbbf30de471e486f7cf356 (patch)
tree0684d05d7e487ebe93463636ed8b5a1bb78e4704 /modules
parent8731d8822216dd3c7587769e3cf5d98690717b0c (diff)
downloadhugo-6cd0784e447f18e009cbbf30de471e486f7cf356.tar.gz
hugo-6cd0784e447f18e009cbbf30de471e486f7cf356.zip
Implement defer
Closes #8086 Closes #12589
Diffstat (limited to 'modules')
-rw-r--r--modules/client.go3
-rw-r--r--modules/client_test.go6
-rw-r--r--modules/collect.go10
-rw-r--r--modules/config.go3
4 files changed, 20 insertions, 2 deletions
diff --git a/modules/client.go b/modules/client.go
index f358f3f75..a6caec23c 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -760,6 +760,9 @@ type ClientConfig struct {
// Absolute path to the project's themes dir.
ThemesDir string
+ // The publish dir.
+ PublishDir string
+
// Eg. "production"
Environment string
diff --git a/modules/client_test.go b/modules/client_test.go
index ea910580f..d727c4586 100644
--- a/modules/client_test.go
+++ b/modules/client_test.go
@@ -51,12 +51,16 @@ github.com/gohugoio/hugoTestModules1_darwin/[email protected] github.com/gohugoio/h
themesDir := filepath.Join(workingDir, "themes")
err = os.Mkdir(themesDir, 0o777)
c.Assert(err, qt.IsNil)
+ publishDir := filepath.Join(workingDir, "public")
+ err = os.Mkdir(publishDir, 0o777)
+ c.Assert(err, qt.IsNil)
ccfg := ClientConfig{
Fs: hugofs.Os,
- WorkingDir: workingDir,
CacheDir: filepath.Join(workingDir, "modcache"),
+ WorkingDir: workingDir,
ThemesDir: themesDir,
+ PublishDir: publishDir,
Exec: hexec.New(security.DefaultConfig),
}
diff --git a/modules/collect.go b/modules/collect.go
index dff71924b..0e59ede19 100644
--- a/modules/collect.go
+++ b/modules/collect.go
@@ -27,6 +27,7 @@ import (
"github.com/bep/debounce"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
+ "github.com/gohugoio/hugo/common/paths"
"github.com/spf13/cast"
@@ -657,7 +658,13 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
// Verify that Source exists
_, err := c.fs.Stat(sourceDir)
if err != nil {
- if strings.HasSuffix(sourceDir, files.FilenameHugoStatsJSON) {
+ if paths.IsSameFilePath(sourceDir, c.ccfg.PublishDir) {
+ // This is a little exotic, but there are use cases for mounting the public folder.
+ // This will typically also be in .gitingore, so create it.
+ if err := c.fs.MkdirAll(sourceDir, 0o755); err != nil {
+ return nil, fmt.Errorf("%s: %q", errMsg, err)
+ }
+ } else if strings.HasSuffix(sourceDir, files.FilenameHugoStatsJSON) {
// A common pattern for Tailwind 3 is to mount that file to get it on the server watch list.
// A common pattern is also to add hugo_stats.json to .gitignore.
@@ -669,6 +676,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
}
f.Close()
} else {
+ c.logger.Warnf("module %q: mount source %q does not exist", owner.Path(), sourceDir)
continue
}
}
diff --git a/modules/config.go b/modules/config.go
index 2f1168d3a..78ec3b6b3 100644
--- a/modules/config.go
+++ b/modules/config.go
@@ -402,6 +402,9 @@ type Mount struct {
// Exclude all files matching the given Glob patterns (string or slice).
ExcludeFiles any
+
+ // Disable watching in watch mode for this mount.
+ DisableWatch bool
}
// Used as key to remove duplicates.