Documentation ¶
Index ¶
- Variables
- func Glob(fs afero.Fs, pattern string, handle func(fi FileMetaInfo) (bool, error)) error
- func LstatIfPossible(fs afero.Fs, path string) (os.FileInfo, bool, error)
- func NewBasePathFs(source afero.Fs, path string) afero.Fs
- func NewReadOnlyFs(source afero.Fs) afero.Fs
- func WalkFilesystems(fs afero.Fs, fn WalkFn) bool
- func WrapFilesystem(container, content afero.Fs) afero.Fs
- type BaseFileDecoratorFs
- type BaseFs
- type ComponentPath
- type ContentClass
- type DirNameOnlyFileInfo
- type DirOnlyOps
- type FileMeta
- type FileMetaInfo
- type FileNameIsDir
- type FilesystemsCollector
- type MetaProvider
- type ReverseLookupProvder
- type RootMapping
- type RootMappingFs
- func (m *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error)
- func (m *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (m *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error)
- func (m *RootMappingFs) Open(name string) (afero.File, error)
- func (m *RootMappingFs) ReverseLookup(filename string) ([]ComponentPath, error)
- func (m *RootMappingFs) ReverseLookupComponent(component, filename string) ([]ComponentPath, error)
- func (m *RootMappingFs) Stat(name string) (os.FileInfo, error)
- type SourceFilesystem
- func (d *SourceFilesystem) MakePathRelative(filename string, checkExists bool) (string, bool)
- func (d *SourceFilesystem) RealDirs(from string) []string
- func (d *SourceFilesystem) RealFilename(rel string) string
- func (d *SourceFilesystem) ReverseLookup(filename string, checkExists bool) ([]ComponentPath, error)
- type SourceFilesystems
- type WalkFn
- type WalkFunc
- type Walkway
Constants ¶
This section is empty.
Variables ¶
var AppendDirsMerger overlayfs.DirsMerger = func(lofi, bofi []fs.DirEntry) []fs.DirEntry { for _, fi1 := range bofi { var found bool if fi1.IsDir() { for _, fi2 := range lofi { if fi2.IsDir() && fi2.Name() == fi1.Name() { found = true break } } } if !found { lofi = append(lofi, fi1) } } return lofi }
AppendDirsMerger merges two directories keeping all regular files with the first slice as the base. Duplicate directories in the second slice will be ignored. This strategy is used for the i18n and data fs where we need all entries.
var LanguageDirsMerger overlayfs.DirsMerger = func(lofi, bofi []fs.DirEntry) []fs.DirEntry { for _, fi1 := range bofi { fim1 := fi1.(FileMetaInfo) var found bool for _, fi2 := range lofi { fim2 := fi2.(FileMetaInfo) if fi1.Name() == fi2.Name() && fim1.Meta().Lang == fim2.Meta().Lang { found = true break } } if !found { lofi = append(lofi, fi1) } } return lofi }
LanguageDirsMerger implements the overlayfs.DirsMerger func, which is used to merge two directories.
var ( // NoOpFs provides a no-op filesystem that implements the afero.Fs // interface. NoOpFs = &noOpFs{} )
Functions ¶
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 LstatIfPossible ¶
LstatIfPossible if the filesystem supports it, use Lstat, else use fs.Stat
func NewBasePathFs ¶
NewBasePathFs creates a new BasePathFs.
func NewReadOnlyFs ¶
NewReadOnlyFs creates a new ReadOnlyFs.
func WalkFilesystems ¶
WalkFilesystems walks fs recursively and calls fn. If fn returns true, walking is stopped.
Types ¶
type BaseFileDecoratorFs ¶
type BaseFileDecoratorFs struct { afero.Fs Decorate func(fi FileNameIsDir, name string) (FileNameIsDir, error) }
func (*BaseFileDecoratorFs) LstatIfPossible ¶
func (*BaseFileDecoratorFs) Open ¶
func (fs *BaseFileDecoratorFs) Open(name string) (afero.File, error)
func (*BaseFileDecoratorFs) Stat ¶
func (fs *BaseFileDecoratorFs) Stat(name string) (os.FileInfo, error)
func (*BaseFileDecoratorFs) UnwrapFilesystem ¶
func (fs *BaseFileDecoratorFs) UnwrapFilesystem() afero.Fs
type BaseFs ¶
type BaseFs struct { // SourceFilesystems contains the different source file systems. *SourceFilesystems TheBigFs *FilesystemsCollector }
BaseFs contains the core base filesystems used by Hugo. The name "base" is used to underline that even if they can be composites, they all have a base path set to a specific resource folder, e.g "/my-project/content". So, no absolute filenames needed.
type ComponentPath ¶
func (ComponentPath) ComponentPathJoined ¶
func (c ComponentPath) ComponentPathJoined() string
type ContentClass ¶
type ContentClass string
const ( ContentClassLeaf ContentClass = "leaf" ContentClassBranch ContentClass = "branch" ContentClassFile ContentClass = "zfile" // Sort below ContentClassContent ContentClass = "zcontent" )
type DirNameOnlyFileInfo ¶
type DirNameOnlyFileInfo struct {
// contains filtered or unexported fields
}
func NewDirNameOnlyFI ¶
func NewDirNameOnlyFI(name string, modTime time.Time) *DirNameOnlyFileInfo
func (*DirNameOnlyFileInfo) IsDir ¶
func (fi *DirNameOnlyFileInfo) IsDir() bool
func (*DirNameOnlyFileInfo) ModTime ¶
func (fi *DirNameOnlyFileInfo) ModTime() time.Time
func (*DirNameOnlyFileInfo) Mode ¶
func (fi *DirNameOnlyFileInfo) Mode() os.FileMode
func (*DirNameOnlyFileInfo) Name ¶
func (fi *DirNameOnlyFileInfo) Name() string
func (*DirNameOnlyFileInfo) Size ¶
func (fi *DirNameOnlyFileInfo) Size() int64
func (*DirNameOnlyFileInfo) Sys ¶
func (fi *DirNameOnlyFileInfo) Sys() any
type DirOnlyOps ¶
type DirOnlyOps interface { io.Closer Name() string Readdir(count int) ([]os.FileInfo, error) Readdirnames(n int) ([]string, error) Stat() (os.FileInfo, error) }
DirOnlyOps is a subset of the afero.File interface covering the methods needed for directory operations.
type FileMeta ¶
type FileMeta struct { PathInfo *paths.Path Name string Filename string Path string PathWalk string OriginalFilename string BaseDir string SourceRoot string MountRoot string Module string Weight int IsOrdered bool IsSymlink bool IsRootFile bool IsProject bool Watch bool Classifier ContentClass SkipDir bool Lang string TranslationBaseName string TranslationBaseNameWithExt string Translations []string Fs afero.Fs OpenFunc func() (afero.File, error) JoinStatFunc func(name string) (FileMetaInfo, error) // Rename the name part of the file (not the directory). // Returns the new name and a boolean indicating if the file // should be included. Rename func(name string, toFrom bool) (string, bool) }
func NewFileMeta ¶
func NewFileMeta() *FileMeta
type FileMetaInfo ¶
func DecorateFileInfo ¶
func DecorateFileInfo(fi FileNameIsDir, opener func() (afero.File, error), filename string, inMeta *FileMeta) FileMetaInfo
func DirEntriesToFileMetaInfos ¶
func DirEntriesToFileMetaInfos(fis []fs.DirEntry) []FileMetaInfo
func NewFileMetaInfo ¶
func NewFileMetaInfo(fi FileNameIsDir, m *FileMeta) FileMetaInfo
type FileNameIsDir ¶
type FilesystemsCollector ¶
type FilesystemsCollector struct { SourceProject afero.Fs // Source for project folders OverlayMounts *overlayfs.OverlayFs OverlayMountsContent *overlayfs.OverlayFs OverlayResources *overlayfs.OverlayFs OverlayFull *overlayfs.OverlayFs // Maps component type (layouts, static, content etc.) an ordered list of // directories representing the overlay filesystems above. OverlayDirs map[string][]FileMetaInfo }
func (*FilesystemsCollector) AddDirs ¶
func (c *FilesystemsCollector) AddDirs(rfs *RootMappingFs)
type MetaProvider ¶
type MetaProvider interface {
Meta() *FileMeta
}
type ReverseLookupProvder ¶
type ReverseLookupProvder interface { ReverseLookup(filename string) ([]ComponentPath, error) ReverseLookupComponent(component, filename string) ([]ComponentPath, error) }
type RootMapping ¶
type RootMapping struct { // The virtual mount. From string FromBase string // The base directory of the virtual mount. //TODO // The source directory or file. To string // The base of To. May be empty if an // absolute path was provided. ToBasedir string // Whether this is a mount in the main project. IsProject bool Meta *FileMeta // File metadata (lang etc.) Fi FileMetaInfo // contains filtered or unexported fields }
RootMapping describes a virtual file or directory mount.
func (RootMapping) Filename ¶
func (r RootMapping) Filename(name string) string
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 (*RootMappingFs) Dirs ¶
func (m *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error)
func (*RootMappingFs) LstatIfPossible ¶
LstatIfPossible returns the os.FileInfo structure describing a given file.
func (*RootMappingFs) Mounts ¶
func (m *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error)
func (*RootMappingFs) Open ¶
func (m *RootMappingFs) Open(name string) (afero.File, error)
Open opens the named file for reading.
func (*RootMappingFs) ReverseLookup ¶
func (m *RootMappingFs) ReverseLookup(filename string) ([]ComponentPath, error)
func (fs *RootMappingFs) ReverseStat(filename string) ([]FileMetaInfo, error)
func (*RootMappingFs) ReverseLookupComponent ¶
func (m *RootMappingFs) ReverseLookupComponent(component, filename string) ([]ComponentPath, error)
type SourceFilesystem ¶
type SourceFilesystem struct { // Name matches one in files.ComponentFolders Name string // This is a virtual composite filesystem. It expects path relative to a context. Fs afero.Fs // The source filesystem (usually the OS filesystem). SourceFs afero.Fs // This filesystem as separate root directories, starting from project and down // to the themes/modules. Dirs []FileMetaInfo // When syncing a source folder to the target (e.g. /public), this may // be set to publish into a subfolder. This is used for static syncing // in multihost mode. PublishFolder string }
A SourceFilesystem holds the filesystem for a given source type in Hugo (data, i18n, layouts, static) and additional metadata to be able to use that filesystem in server mode.
func (*SourceFilesystem) MakePathRelative ¶
func (d *SourceFilesystem) MakePathRelative(filename string, checkExists bool) (string, bool)
MakePathRelative creates a relative path from the given filename.
func (*SourceFilesystem) RealDirs ¶
func (d *SourceFilesystem) RealDirs(from string) []string
RealDirs gets a list of absolute paths to directories starting from the given path.
func (*SourceFilesystem) RealFilename ¶
func (d *SourceFilesystem) RealFilename(rel string) string
func (*SourceFilesystem) ReverseLookup ¶
func (d *SourceFilesystem) ReverseLookup(filename string, checkExists bool) ([]ComponentPath, error)
ReverseLookup returns the component paths for the given filename.
type SourceFilesystems ¶
type SourceFilesystems struct { Content *SourceFilesystem // set Data *SourceFilesystem I18n *SourceFilesystem Layouts *SourceFilesystem // set Archetypes *SourceFilesystem Assets *SourceFilesystem // Writable filesystem on top the project's resources directory, // with any sub module's resource fs layered below. ResourcesCache afero.Fs // The work folder (may be a composite of project and theme components). Work afero.Fs // When in multihost we have one static filesystem per language. The sync // static files is currently done outside of the Hugo build (where there is // a concept of a site per language). // When in non-multihost mode there will be one entry in this map with a blank key. Static map[string]*SourceFilesystem // All the /static dirs (including themes/modules). StaticDirs []FileMetaInfo }
SourceFilesystems contains the different source file systems. These can be composite file systems (theme and project etc.), and they have all root set to the source type the provides: data, i18n, static, layouts.