package hugofs
import "github.com/gohugoio/hugo/hugofs"
Package hugofs provides the file systems used by Hugo.
Package hugofs provides the file systems used by Hugo.
Index ¶
- Variables
- func DecorateBasePathFs(base *afero.BasePathFs) afero.Fs
- func Glob(fs afero.Fs, pattern string, handle func(fi FileMetaInfo) (bool, error)) error
- func NewBaseFileDecorator(fs afero.Fs) afero.Fs
- func NewCreateCountingFs(fs afero.Fs) afero.Fs
- func NewFilterFs(fs afero.Fs) (afero.Fs, error)
- func NewHashingFs(delegate afero.Fs, hashReceiver FileHashReceiver) afero.Fs
- func NewLanguageCompositeFs(base, overlay afero.Fs) afero.Fs
- func NewLanguageFs(langs map[string]int, fs afero.Fs) (afero.Fs, error)
- func NewNoSymlinkFs(fs afero.Fs, logger *loggers.Logger, allowFiles bool) afero.Fs
- func NewSliceFs(dirs ...FileMetaInfo) (afero.Fs, error)
- func NewStacktracerFs(fs afero.Fs, pattern string) afero.Fs
- type DuplicatesReporter
- type FileHashReceiver
- type FileMeta
- func (f FileMeta) Classifier() string
- func (f FileMeta) Filename() string
- func (f FileMeta) Fs() afero.Fs
- func (f FileMeta) GetBool(key string) bool
- func (f FileMeta) GetInt(key string) int
- func (f FileMeta) GetOpener() func() (afero.File, error)
- func (f FileMeta) GetString(key string) string
- func (f FileMeta) IsOrdered() bool
- func (f FileMeta) IsSymlink() bool
- func (f FileMeta) Lang() string
- func (f FileMeta) Name() string
- func (f FileMeta) Open() (afero.File, error)
- func (f FileMeta) Ordinal() int
- func (f FileMeta) OriginalFilename() string
- func (f FileMeta) Path() string
- func (f FileMeta) SkipDir() bool
- func (f FileMeta) String() string
- func (f FileMeta) TranslationBaseName() string
- func (f FileMeta) TranslationBaseNameWithExt() string
- func (f FileMeta) Translations() []string
- func (f FileMeta) Watch() bool
- func (f FileMeta) Weight() int
- type FileMetaInfo
- type FilterFs
- func (fs *FilterFs) Chmod(n string, m os.FileMode) error
- func (fs *FilterFs) Chtimes(n string, a, m time.Time) error
- func (fs *FilterFs) Create(n string) (afero.File, error)
- func (fs *FilterFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (fs *FilterFs) Mkdir(n string, p os.FileMode) error
- func (fs *FilterFs) MkdirAll(n string, p os.FileMode) error
- func (fs *FilterFs) Name() string
- func (fs *FilterFs) Open(name string) (afero.File, error)
- func (fs *FilterFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)
- func (fs *FilterFs) ReadDir(name string) ([]os.FileInfo, error)
- func (fs *FilterFs) Remove(n string) error
- func (fs *FilterFs) RemoveAll(p string) error
- func (fs *FilterFs) Rename(o, n string) error
- func (fs *FilterFs) Stat(name string) (os.FileInfo, error)
- type Fs
- func NewDefault(cfg config.Provider) *Fs
- func NewFrom(fs afero.Fs, cfg config.Provider) *Fs
- func NewMem(cfg config.Provider) *Fs
- type Reseter
- type RootMapping
- type RootMappingFs
- func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error)
- func NewRootMappingFsFromFromTo(fs afero.Fs, fromTo ...string) (*RootMappingFs, error)
- func (fs *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error)
- func (fs RootMappingFs) Filter(f func(m RootMapping) bool) *RootMappingFs
- func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (fs *RootMappingFs) Open(name string) (afero.File, error)
- func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error)
- type SliceFs
- func (fs *SliceFs) Chmod(n string, m os.FileMode) error
- func (fs *SliceFs) Chtimes(n string, a, m time.Time) error
- func (fs *SliceFs) Create(n string) (afero.File, error)
- func (fs *SliceFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (fs *SliceFs) Mkdir(n string, p os.FileMode) error
- func (fs *SliceFs) MkdirAll(n string, p os.FileMode) error
- func (fs *SliceFs) Name() string
- func (fs *SliceFs) Open(name string) (afero.File, error)
- func (fs *SliceFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)
- func (fs *SliceFs) ReadDir(name string) ([]os.FileInfo, error)
- func (fs *SliceFs) Remove(n string) error
- func (fs *SliceFs) RemoveAll(p string) error
- func (fs *SliceFs) Rename(o, n string) error
- func (fs *SliceFs) Stat(name string) (os.FileInfo, error)
- type WalkFunc
- type WalkHook
- type Walkway
- type WalkwayConfig
Variables ¶
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) { m := make(map[string]FileMetaInfo) getKey := func(fim FileMetaInfo) string { return path.Join(fim.Meta().Lang(), fim.Name()) } for _, fi := range lofi { fim := fi.(FileMetaInfo) m[getKey(fim)] = fim } for _, fi := range bofi { fim := fi.(FileMetaInfo) key := getKey(fim) _, found := m[key] if !found { m[key] = fim } } merged := make([]os.FileInfo, len(m)) i := 0 for _, v := range m { merged[i] = v i++ } return merged, nil }
LanguageDirsMerger implements the afero.DirsMerger interface, which is used to merge two directories.
var ( // NoOpFs provides a no-op filesystem that implements the afero.Fs // interface. NoOpFs = &noOpFs{} )
Functions ¶
func DecorateBasePathFs ¶
func DecorateBasePathFs(base *afero.BasePathFs) afero.Fs
DecorateBasePathFs adds Path info to files and directories in the provided BasePathFs, using the base as base.
func Glob ¶
Glob walks the fs and passes all matches to the handle func. The handle func can return true to signal a stop.
func NewBaseFileDecorator ¶
NewBaseFileDecorator decorates the given Fs to provide the real filename and an Opener func. If
func NewCreateCountingFs ¶
func NewFilterFs ¶
func NewHashingFs ¶
func NewHashingFs(delegate afero.Fs, hashReceiver FileHashReceiver) afero.Fs
NewHashingFs creates a new filesystem that will receive MD5 checksums of any written file content on Close. Note that this is probably not a good idea for "full build" situations, but when doing fast render mode, the amount of files published is low, and it would be really nice to know exactly which of these files where actually changed. Note that this will only work for file operations that use the io.Writer to write content to file, but that is fine for the "publish content" use case.
func NewLanguageCompositeFs ¶
NewLanguageCompositeFs creates a composite and language aware filesystem. This is a hybrid filesystem. To get a specific file in Open, Stat etc., use the full filename to the target filesystem. This information is available in Readdir, Stat etc. via the special LanguageFileInfo FileInfo implementation.
func NewLanguageFs ¶
func NewNoSymlinkFs ¶
NewNoSymlinkFs creates a new filesystem that prevents symlinks.
func NewSliceFs ¶
func NewSliceFs(dirs ...FileMetaInfo) (afero.Fs, error)
func NewStacktracerFs ¶
NewStacktracerFs wraps the given fs printing stack traces for file creates matching the given regexp pattern.
Types ¶
type DuplicatesReporter ¶
type DuplicatesReporter interface { ReportDuplicates() string }
DuplicatesReporter reports about duplicate filenames.
type FileHashReceiver ¶
type FileHashReceiver interface { OnFileClose(name, md5sum string) }
FileHashReceiver will receive the filename an the content's MD5 sum on file close.
type FileMeta ¶
type FileMeta map[string]interface{}
func (FileMeta) Classifier ¶
func (FileMeta) Filename ¶
func (FileMeta) Fs ¶
func (FileMeta) GetBool ¶
func (FileMeta) GetInt ¶
func (FileMeta) GetOpener ¶
func (FileMeta) GetString ¶
func (FileMeta) IsOrdered ¶
func (FileMeta) IsSymlink ¶
IsSymlink returns whether this comes from a symlinked file or directory.
func (FileMeta) Lang ¶
func (FileMeta) Name ¶
func (FileMeta) Open ¶
func (FileMeta) Ordinal ¶
func (FileMeta) OriginalFilename ¶
func (FileMeta) Path ¶
func (FileMeta) SkipDir ¶
func (FileMeta) String ¶
func (FileMeta) TranslationBaseName ¶
func (FileMeta) TranslationBaseNameWithExt ¶
func (FileMeta) Translations ¶
func (FileMeta) Watch ¶
func (FileMeta) Weight ¶
type FileMetaInfo ¶
func NewFileMetaInfo ¶
func NewFileMetaInfo(fi os.FileInfo, m FileMeta) FileMetaInfo
type FilterFs ¶
type FilterFs struct {
// contains filtered or unexported fields
}
FilterFs is an ordered composite filesystem.
func (*FilterFs) Chmod ¶
func (*FilterFs) Chtimes ¶
func (*FilterFs) Create ¶
func (*FilterFs) LstatIfPossible ¶
func (*FilterFs) Mkdir ¶
func (*FilterFs) MkdirAll ¶
func (*FilterFs) Name ¶
func (*FilterFs) Open ¶
func (*FilterFs) OpenFile ¶
func (*FilterFs) ReadDir ¶
func (*FilterFs) Remove ¶
func (*FilterFs) RemoveAll ¶
func (*FilterFs) Rename ¶
func (*FilterFs) Stat ¶
type Fs ¶
type Fs struct { // Source is Hugo's source file system. Source afero.Fs // Destination is Hugo's destination file system. Destination afero.Fs // Os is an OS file system. // NOTE: Field is currently unused. Os afero.Fs // WorkingDir is a read-only file system // restricted to the project working dir. WorkingDir *afero.BasePathFs }
Fs abstracts the file system to separate source and destination file systems and allows both to be mocked for testing.
func NewDefault ¶
NewDefault creates a new Fs with the OS file system as source and destination file systems.
func NewFrom ¶
NewFrom creates a new Fs based on the provided Afero Fs as source and destination file systems. Useful for testing.
func NewMem ¶
NewMem creates a new Fs with the MemMapFs as source and destination file systems. Useful for testing.
type Reseter ¶
type Reseter interface {
Reset()
}
Reseter is implemented by some of the stateful filesystems.
type RootMapping ¶
type RootMapping struct { From string To string Meta FileMeta // File metadata (lang etc.) // contains filtered or unexported fields }
type RootMappingFs ¶
A RootMappingFs maps several roots into one. Note that the root of this filesystem is directories only, and they will be returned in Readdir and Readdirnames in the order given.
func NewRootMappingFs ¶
func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error)
NewRootMappingFs creates a new RootMappingFs on top of the provided with of root mappings with some optional metadata about the root. Note that From represents a virtual root that maps to the actual filename in To.
func NewRootMappingFsFromFromTo ¶
func NewRootMappingFsFromFromTo(fs afero.Fs, fromTo ...string) (*RootMappingFs, error)
NewRootMappingFsFromFromTo is a convenicence variant of NewRootMappingFs taking From and To as string pairs.
func (*RootMappingFs) Dirs ¶
func (fs *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error)
func (RootMappingFs) Filter ¶
func (fs RootMappingFs) Filter(f func(m RootMapping) bool) *RootMappingFs
Filter creates a copy of this filesystem with the applied filter.
func (*RootMappingFs) LstatIfPossible ¶
LstatIfPossible returns the os.FileInfo structure describing a given file.
func (*RootMappingFs) Open ¶
func (fs *RootMappingFs) Open(name string) (afero.File, error)
Open opens the namedrootMappingFile file for reading.
func (*RootMappingFs) Stat ¶
func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error)
Stat returns the os.FileInfo structure describing a given file. If there is an error, it will be of type *os.PathError.
type SliceFs ¶
type SliceFs struct {
// contains filtered or unexported fields
}
SliceFs is an ordered composite filesystem.
func (*SliceFs) Chmod ¶
func (*SliceFs) Chtimes ¶
func (*SliceFs) Create ¶
func (*SliceFs) LstatIfPossible ¶
func (*SliceFs) Mkdir ¶
func (*SliceFs) MkdirAll ¶
func (*SliceFs) Name ¶
func (*SliceFs) Open ¶
func (*SliceFs) OpenFile ¶
func (*SliceFs) ReadDir ¶
func (*SliceFs) Remove ¶
func (*SliceFs) RemoveAll ¶
func (*SliceFs) Rename ¶
func (*SliceFs) Stat ¶
type WalkFunc ¶
type WalkFunc func(path string, info FileMetaInfo, err error) error
type WalkHook ¶
type WalkHook func(dir FileMetaInfo, path string, readdir []FileMetaInfo) ([]FileMetaInfo, error)
type Walkway ¶
type Walkway struct {
// contains filtered or unexported fields
}
func NewWalkway ¶
func NewWalkway(cfg WalkwayConfig) *Walkway
func (*Walkway) Walk ¶
type WalkwayConfig ¶
type WalkwayConfig struct { Fs afero.Fs Root string BasePath string Logger *loggers.Logger // One or both of these may be pre-set. Info FileMetaInfo DirEntries []FileMetaInfo WalkFn WalkFunc HookPre WalkHook HookPost WalkHook }
Source Files ¶
createcounting_fs.go decorators.go fileinfo.go filter_fs.go fs.go glob.go hashing_fs.go language_composite_fs.go noop_fs.go nosymlink_fs.go rootmapping_fs.go slice_fs.go stacktracer_fs.go walk.go
Directories ¶
Path | Synopsis |
---|---|
hugofs/files | |
hugofs/glob |
- Version
- v0.61.0
- Published
- Dec 11, 2019
- Platform
- darwin/amd64
- Imports
- 27 packages
- Last checked
- 30 minutes ago –
Tools for package owners.