diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-12-30 10:50:00 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-01-01 18:19:49 +0100 |
commit | ff6253bc7cf745e9c0127ddc9006da3c2c00c738 (patch) | |
tree | 9e80cc607575e516f4f93e0f16c3e82df3bafdb5 /hugolib/filesystems | |
parent | aa4ccb8a1e9b8aa17397acf34049a2aa16b0b6cb (diff) | |
download | hugo-ff6253bc7cf745e9c0127ddc9006da3c2c00c738.tar.gz hugo-ff6253bc7cf745e9c0127ddc9006da3c2c00c738.zip |
Support files in content mounts
This commit is a general improvement of handling if single file mounts.
Fixes #6684
Fixes #6696
Diffstat (limited to 'hugolib/filesystems')
-rw-r--r-- | hugolib/filesystems/basefs.go | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index d931db4d1..cf9ff3c38 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -18,6 +18,7 @@ package filesystems import ( "io" "os" + "path" "path/filepath" "strings" "sync" @@ -55,6 +56,8 @@ type BaseFs struct { theBigFs *filesystemsCollector } +// TODO(bep) we can get regular files in here and that is fine, but +// we need to clean up the naming. func (fs *BaseFs) WatchDirs() []hugofs.FileMetaInfo { var dirs []hugofs.FileMetaInfo for _, dir := range fs.AllDirs() { @@ -62,7 +65,6 @@ func (fs *BaseFs) WatchDirs() []hugofs.FileMetaInfo { dirs = append(dirs, dir) } } - return dirs } @@ -90,7 +92,7 @@ func (b *BaseFs) RelContentDir(filename string) string { for _, dir := range b.SourceFilesystems.Content.Dirs { dirname := dir.Meta().Filename() if strings.HasPrefix(filename, dirname) { - rel := strings.TrimPrefix(filename, dirname) + rel := path.Join(dir.Meta().Path(), strings.TrimPrefix(filename, dirname)) return strings.TrimPrefix(rel, filePathSeparator) } } @@ -298,8 +300,16 @@ func (d *SourceFilesystem) Contains(filename string) bool { func (d *SourceFilesystem) Path(filename string) string { for _, dir := range d.Dirs { meta := dir.Meta() + if !dir.IsDir() { + if filename == meta.Filename() { + return meta.PathFile() + } + continue + } + if strings.HasPrefix(filename, meta.Filename()) { p := strings.TrimPrefix(strings.TrimPrefix(filename, meta.Filename()), filePathSeparator) + p = path.Join(meta.PathFile(), p) return p } } @@ -530,11 +540,11 @@ func (b *sourceFilesystemsBuilder) createModFs( fromToStatic []hugofs.RootMapping ) - absPathify := func(path string) string { + absPathify := func(path string) (string, string) { if filepath.IsAbs(path) { - return path + return "", path } - return paths.AbsPathify(md.dir, path) + return md.dir, paths.AbsPathify(md.dir, path) } for _, mount := range md.Mounts() { @@ -544,9 +554,12 @@ func (b *sourceFilesystemsBuilder) createModFs( mountWeight++ } + base, filename := absPathify(mount.Source) + rm := hugofs.RootMapping{ - From: mount.Target, - To: absPathify(mount.Source), + From: mount.Target, + To: filename, + ToBasedir: base, Meta: hugofs.FileMeta{ "watch": md.Watch(), "mountWeight": mountWeight, @@ -621,7 +634,8 @@ func (b *sourceFilesystemsBuilder) createModFs( if md.isMainProject { return b.p.AbsResourcesDir } - return absPathify(files.FolderResources) + _, filename := absPathify(files.FolderResources) + return filename } if collector.overlayMounts == nil { |