package hugofs
import "github.com/gohugoio/hugo/hugofs"
Package hugofs provides the file systems used by Hugo.
Index ¶
- Variables
- func NewLanguageCompositeFs(base afero.Fs, overlay *LanguageFs) afero.Fs
- type FilePather
- type Fs
- func NewDefault(cfg config.Provider) *Fs
- func NewFrom(fs afero.Fs, cfg config.Provider) *Fs
- func NewMem(cfg config.Provider) *Fs
- type LanguageAnnouncer
- type LanguageFileInfo
- func (fi *LanguageFileInfo) BaseDir() string
- func (fi *LanguageFileInfo) Filename() string
- func (fi *LanguageFileInfo) Lang() string
- func (fi *LanguageFileInfo) Name() string
- func (fi *LanguageFileInfo) Path() string
- func (fi *LanguageFileInfo) RealName() string
- func (fi *LanguageFileInfo) TranslationBaseName() string
- type LanguageFs
- func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs
- func (fs *LanguageFs) Lang() string
- func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
- func (fs *LanguageFs) Open(name string) (afero.File, error)
- func (fs *LanguageFs) Stat(name string) (os.FileInfo, error)
- type RootMappingFs
Variables ¶
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) { m := make(map[string]*LanguageFileInfo) for _, fi := range lofi { fil, ok := fi.(*LanguageFileInfo) if !ok { return nil, fmt.Errorf("received %T, expected *LanguageFileInfo", fi) } m[fil.virtualName] = fil } for _, fi := range bofi { fil, ok := fi.(*LanguageFileInfo) if !ok { return nil, fmt.Errorf("received %T, expected *LanguageFileInfo", fi) } existing, found := m[fil.virtualName] if !found || existing.weight < fil.weight { m[fil.virtualName] = fil } } merged := make([]os.FileInfo, len(m)) i := 0 for _, v := range m { merged[i] = v i++ } return merged, nil }
var (
NoOpFs = &noOpFs{}
)
Os points to an Os Afero file system.
Functions ¶
func NewLanguageCompositeFs ¶
func NewLanguageCompositeFs(base afero.Fs, overlay *LanguageFs) afero.Fs
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.
Types ¶
type FilePather ¶
type FilePather interface { // Filename gets the full path and filename to the file. Filename() string // Path gets the content relative path including file name and extension. // The directory is relative to the content root where "content" is a broad term. Path() string // RealName is FileInfo.Name in its original form. RealName() string BaseDir() string }
FilePather is aware of its file's location.
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 LanguageAnnouncer ¶
LanguageAnnouncer is aware of its language.
type LanguageFileInfo ¶
func (*LanguageFileInfo) BaseDir ¶
func (fi *LanguageFileInfo) BaseDir() string
func (*LanguageFileInfo) Filename ¶
func (fi *LanguageFileInfo) Filename() string
func (*LanguageFileInfo) Lang ¶
func (fi *LanguageFileInfo) Lang() string
func (*LanguageFileInfo) Name ¶
func (fi *LanguageFileInfo) Name() string
Name is the name of the file within this filesystem without any path info. It will be marked with language information so we can identify it as ours.
func (*LanguageFileInfo) Path ¶
func (fi *LanguageFileInfo) Path() string
func (*LanguageFileInfo) RealName ¶
func (fi *LanguageFileInfo) RealName() string
func (*LanguageFileInfo) TranslationBaseName ¶
func (fi *LanguageFileInfo) TranslationBaseName() string
TranslationBaseName returns the base filename without any extension or language identificator.
type LanguageFs ¶
func NewLanguageFs ¶
func (*LanguageFs) Lang ¶
func (fs *LanguageFs) Lang() string
func (*LanguageFs) LstatIfPossible ¶
func (*LanguageFs) Open ¶
func (fs *LanguageFs) Open(name string) (afero.File, error)
func (*LanguageFs) Stat ¶
func (fs *LanguageFs) Stat(name string) (os.FileInfo, error)
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, fromTo ...string) (*RootMappingFs, error)
NewRootMappingFs creates a new RootMappingFs on top of the provided with a list of from, to string pairs of root mappings. Note that 'from' represents a virtual root that maps to the actual filename in 'to'.
func (*RootMappingFs) LstatIfPossible ¶
func (*RootMappingFs) Open ¶
func (fs *RootMappingFs) Open(name string) (afero.File, error)
func (*RootMappingFs) Stat ¶
func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error)
Source Files ¶
fs.go language_composite_fs.go language_fs.go noop_fs.go rootmapping_fs.go
- Version
- v0.42.2
- Published
- Jun 28, 2018
- Platform
- darwin/amd64
- Imports
- 9 packages
- Last checked
- 31 minutes ago –
Tools for package owners.