package hugofs

import "github.com/gohugoio/hugo/hugofs"

Package hugofs provides the file systems used by Hugo.

Index

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
}

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{}
)
var Os = &afero.OsFs{}

Os points to an Os Afero file system.

Functions

func NewCreateCountingFs

func NewCreateCountingFs(fs afero.Fs) afero.Fs

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

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.

func NewNoLstatFs

func NewNoLstatFs(fs afero.Fs) afero.Fs

NewNoLstatFs creates a new filesystem with no Lstat support.

func NewStacktracerFs

func NewStacktracerFs(fs afero.Fs, pattern string) afero.Fs

NewStacktracerFs wraps the given fs printing stack traces for file creates matching the given regexp pattern.

Types

type BasePathRealFilenameFs

type BasePathRealFilenameFs struct {
	*afero.BasePathFs
}

BasePathRealFilenameFs is a thin wrapper around afero.BasePathFs that provides the real filename in Stat and LstatIfPossible.

func NewBasePathRealFilenameFs

func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs

NewBasePathRealFilenameFs returns a new BasePathRealFilenameFs instance using base.

func (*BasePathRealFilenameFs) LstatIfPossible

func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible returns the os.FileInfo structure describing a given file. It attempts to use Lstat if supported or defers to the os. In addition to the FileInfo, a boolean is returned telling whether Lstat was called.

func (*BasePathRealFilenameFs) Stat

func (b *BasePathRealFilenameFs) 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 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 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

func NewDefault(cfg config.Provider) *Fs

NewDefault creates a new Fs with the OS file system as source and destination file systems.

func NewFrom

func NewFrom(fs afero.Fs, cfg config.Provider) *Fs

NewFrom creates a new Fs based on the provided Afero Fs as source and destination file systems. Useful for testing.

func NewMem

func NewMem(cfg config.Provider) *Fs

NewMem creates a new Fs with the MemMapFs as source and destination file systems. Useful for testing.

type LanguageAnnouncer

type LanguageAnnouncer interface {
	Lang() string
	TranslationBaseName() string
}

LanguageAnnouncer is aware of its language.

type LanguageFileInfo

type LanguageFileInfo struct {
	os.FileInfo
	// contains filtered or unexported fields
}

LanguageFileInfo is a super-set of os.FileInfo with additional information about the file in relation to its Hugo language.

func (*LanguageFileInfo) BaseDir

func (fi *LanguageFileInfo) BaseDir() string

BaseDir returns a file's base directory (ie. "/my/base").

func (*LanguageFileInfo) Filename

func (fi *LanguageFileInfo) Filename() string

Filename returns a file's real filename including the base (ie. "/my/base/sect/page.md").

func (*LanguageFileInfo) Lang

func (fi *LanguageFileInfo) Lang() string

Lang returns a file's language (ie. "sv").

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 (ie. "__hugofs_sv_page.md").

func (*LanguageFileInfo) Path

func (fi *LanguageFileInfo) Path() string

Path returns a file's filename relative to the base (ie. "sect/page.md").

func (*LanguageFileInfo) RealName

func (fi *LanguageFileInfo) RealName() string

RealName returns a file's real base name (ie. "page.md").

func (*LanguageFileInfo) TranslationBaseName

func (fi *LanguageFileInfo) TranslationBaseName() string

TranslationBaseName returns the base filename without any extension or language identifiers (ie. "page").

type LanguageFs

type LanguageFs struct {
	afero.Fs
	// contains filtered or unexported fields
}

LanguageFs represents a language filesystem.

func NewLanguageFs

func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs

NewLanguageFs creates a new language filesystem.

func (*LanguageFs) Lang

func (fs *LanguageFs) Lang() string

Lang returns a language filesystem's language (ie. "sv").

func (*LanguageFs) LstatIfPossible

func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible returns the os.FileInfo structure describing a given file. It attempts to use Lstat if supported or defers to the os. In addition to the FileInfo, a boolean is returned telling whether Lstat was called.

func (*LanguageFs) Open

func (fs *LanguageFs) Open(name string) (afero.File, error)

Open opens the named file for reading.

func (*LanguageFs) Stat

func (fs *LanguageFs) Stat(name string) (os.FileInfo, error)

Stat returns the os.FileInfo of a given file.

type RealFilenameInfo

type RealFilenameInfo interface {
	os.FileInfo

	// This is the real filename to the file in the underlying filesystem.
	RealFilename() string
}

RealFilenameInfo is a thin wrapper around os.FileInfo adding the real filename.

type Reseter

type Reseter interface {
	Reset()
}

Reseter is implemented by some of the stateful filesystems.

type RootMappingFs

type RootMappingFs struct {
	afero.Fs
	// contains filtered or unexported fields
}

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 (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible returns the os.FileInfo structure describing a given file. It attempts to use Lstat if supported or defers to the os. In addition to the FileInfo, a boolean is returned telling whether Lstat was called.

func (*RootMappingFs) Open

func (fs *RootMappingFs) Open(name string) (afero.File, error)

Open opens the named 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.

Source Files

basepath_real_filename_fs.go createcounting_fs.go fs.go hashing_fs.go language_composite_fs.go language_fs.go nolstat_fs.go noop_fs.go rootmapping_fs.go stacktracer_fs.go

Version
v0.55.0
Published
Apr 8, 2019
Platform
js/wasm
Imports
17 packages
Last checked
2 hours ago

Tools for package owners.