diff options
Diffstat (limited to 'hugofs')
-rw-r--r-- | hugofs/hasbytes_fs.go | 23 | ||||
-rw-r--r-- | hugofs/rootmapping_fs.go | 2 |
2 files changed, 18 insertions, 7 deletions
diff --git a/hugofs/hasbytes_fs.go b/hugofs/hasbytes_fs.go index 238fbc9c4..ac9e881ef 100644 --- a/hugofs/hasbytes_fs.go +++ b/hugofs/hasbytes_fs.go @@ -28,12 +28,12 @@ var ( type hasBytesFs struct { afero.Fs shouldCheck func(name string) bool - hasBytesCallback func(name string, match bool) - pattern []byte + hasBytesCallback func(name string, match []byte) + patterns [][]byte } -func NewHasBytesReceiver(delegate afero.Fs, shouldCheck func(name string) bool, hasBytesCallback func(name string, match bool), pattern []byte) afero.Fs { - return &hasBytesFs{Fs: delegate, shouldCheck: shouldCheck, hasBytesCallback: hasBytesCallback, pattern: pattern} +func NewHasBytesReceiver(delegate afero.Fs, shouldCheck func(name string) bool, hasBytesCallback func(name string, match []byte), patterns ...[]byte) afero.Fs { + return &hasBytesFs{Fs: delegate, shouldCheck: shouldCheck, hasBytesCallback: hasBytesCallback, patterns: patterns} } func (fs *hasBytesFs) UnwrapFilesystem() afero.Fs { @@ -60,10 +60,15 @@ func (fs *hasBytesFs) wrapFile(f afero.File) afero.File { if !fs.shouldCheck(f.Name()) { return f } + patterns := make([]*hugio.HasBytesPattern, len(fs.patterns)) + for i, p := range fs.patterns { + patterns[i] = &hugio.HasBytesPattern{Pattern: p} + } + return &hasBytesFile{ File: f, hbw: &hugio.HasBytesWriter{ - Pattern: fs.pattern, + Patterns: patterns, }, hasBytesCallback: fs.hasBytesCallback, } @@ -74,7 +79,7 @@ func (fs *hasBytesFs) Name() string { } type hasBytesFile struct { - hasBytesCallback func(name string, match bool) + hasBytesCallback func(name string, match []byte) hbw *hugio.HasBytesWriter afero.File } @@ -88,6 +93,10 @@ func (h *hasBytesFile) Write(p []byte) (n int, err error) { } func (h *hasBytesFile) Close() error { - h.hasBytesCallback(h.Name(), h.hbw.Match) + for _, p := range h.hbw.Patterns { + if p.Match { + h.hasBytesCallback(h.Name(), p.Pattern) + } + } return h.File.Close() } diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go index c91403c79..2ecd88e9e 100644 --- a/hugofs/rootmapping_fs.go +++ b/hugofs/rootmapping_fs.go @@ -323,6 +323,7 @@ type ComponentPath struct { Component string Path string Lang string + Watch bool } func (c ComponentPath) ComponentPathJoined() string { @@ -376,6 +377,7 @@ func (fs *RootMappingFs) ReverseLookupComponent(component, filename string) ([]C Component: first.FromBase, Path: paths.ToSlashTrimLeading(filename), Lang: first.Meta.Lang, + Watch: first.Meta.Watch, }) } |