diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-04 18:24:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-16 18:01:29 +0200 |
commit | 241b21b0fd34d91fccb2ce69874110dceae6f926 (patch) | |
tree | d4e0118eac7e9c42f065815447a70805f8d6ad3e /hugolib/filesystems/basefs.go | |
parent | 6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff) |
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.
Also,
* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.
Closes #10896
Closes #10620
Diffstat (limited to 'hugolib/filesystems/basefs.go')
-rw-r--r-- | hugolib/filesystems/basefs.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 377428325..b90111e26 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -441,6 +441,8 @@ func WithBaseFs(b *BaseFs) func(*BaseFs) error { } } +var counter int + // NewBase builds the filesystems used by Hugo given the paths and options provided.NewBase func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) error) (*BaseFs, error) { fs := p.Fs @@ -449,14 +451,14 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err } publishFs := hugofs.NewBaseFileDecorator(fs.PublishDir) - sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir)) + sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.Cfg.BaseConfig().WorkingDir)) publishFsStatic := fs.PublishDirStatic var buildMu Lockable - if p.Cfg.GetBool("noBuildLock") || htesting.IsTest { + if p.Cfg.NoBuildLock() || htesting.IsTest { buildMu = &fakeLockfileMutex{} } else { - buildMu = lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)) + buildMu = lockedfile.MutexAt(filepath.Join(p.Cfg.BaseConfig().WorkingDir, lockFileBuild)) } b := &BaseFs{ @@ -554,7 +556,7 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) { contentDirs := b.theBigFs.overlayDirs[files.ComponentFolderContent] contentBfs := afero.NewBasePathFs(b.theBigFs.overlayMountsContent, files.ComponentFolderContent) - contentFs, err := hugofs.NewLanguageFs(b.p.LanguagesDefaultFirst.AsOrdinalSet(), contentBfs) + contentFs, err := hugofs.NewLanguageFs(b.p.Cfg.LanguagesDefaultFirst().AsOrdinalSet(), contentBfs) if err != nil { return nil, fmt.Errorf("create content filesystem: %w", err) } @@ -585,9 +587,10 @@ func (b *sourceFilesystemsBuilder) Build() (*SourceFilesystems, error) { func (b *sourceFilesystemsBuilder) createMainOverlayFs(p *paths.Paths) (*filesystemsCollector, error) { var staticFsMap map[string]*overlayfs.OverlayFs - if b.p.Cfg.GetBool("multihost") { + if b.p.Cfg.IsMultihost() { + languages := b.p.Cfg.Languages() staticFsMap = make(map[string]*overlayfs.OverlayFs) - for _, l := range b.p.Languages { + for _, l := range languages { staticFsMap[l.Lang] = overlayfs.New(overlayfs.Options{}) } } @@ -605,7 +608,7 @@ func (b *sourceFilesystemsBuilder) createMainOverlayFs(p *paths.Paths) (*filesys overlayResources: overlayfs.New(overlayfs.Options{FirstWritable: true}), } - mods := p.AllModules + mods := p.AllModules() mounts := make([]mountsDescriptor, len(mods)) @@ -671,7 +674,6 @@ func (b *sourceFilesystemsBuilder) createOverlayFs( } for i, mount := range md.Mounts() { - // Add more weight to early mounts. // When two mounts contain the same filename, // the first entry wins. @@ -705,7 +707,7 @@ func (b *sourceFilesystemsBuilder) createOverlayFs( lang := mount.Lang if lang == "" && isContentMount { - lang = b.p.DefaultContentLanguage + lang = b.p.Cfg.DefaultContentLanguage() } rm.Meta.Lang = lang @@ -745,17 +747,15 @@ func (b *sourceFilesystemsBuilder) createOverlayFs( collector.addDirs(rmfsStatic) if collector.staticPerLanguage != nil { - for _, l := range b.p.Languages { + for _, l := range b.p.Cfg.Languages() { lang := l.Lang lfs := rmfsStatic.Filter(func(rm hugofs.RootMapping) bool { rlang := rm.Meta.Lang return rlang == "" || rlang == lang }) - bfs := afero.NewBasePathFs(lfs, files.ComponentFolderStatic) collector.staticPerLanguage[lang] = collector.staticPerLanguage[lang].Append(bfs) - } } |