hugofs

package
v0.40.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hugofs provides the file systems used by Hugo.

Index

Constants

This section is empty.

Variables

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

Os points to an Os Afero file system.

Functions

func NewLanguageCompositeFs added in v0.38.1

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 BaseFs added in v0.38.1

type BaseFs struct {
	// The filesystem used to capture content. This can be a composite and
	// language aware file system.
	ContentFs afero.Fs

	// The filesystem used to store resources (processed images etc.).
	// This usually maps to /my-project/resources.
	ResourcesFs afero.Fs

	// The filesystem used to publish the rendered site.
	// This usually maps to /my-project/public.
	PublishFs afero.Fs
}

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 FilePather added in v0.38.1

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 added in v0.20.1

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 added in v0.20.1

func NewDefault(cfg config.Provider) *Fs

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

func NewFrom added in v0.20.1

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 added in v0.20.1

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 added in v0.38.1

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

LanguageAnnouncer is aware of its language.

type LanguageFileInfo added in v0.38.1

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

func (*LanguageFileInfo) BaseDir added in v0.38.1

func (fi *LanguageFileInfo) BaseDir() string

func (*LanguageFileInfo) Filename added in v0.38.1

func (fi *LanguageFileInfo) Filename() string

func (*LanguageFileInfo) Lang added in v0.38.1

func (fi *LanguageFileInfo) Lang() string

func (*LanguageFileInfo) Name added in v0.38.1

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 added in v0.38.1

func (fi *LanguageFileInfo) Path() string

func (*LanguageFileInfo) RealName added in v0.38.1

func (fi *LanguageFileInfo) RealName() string

func (*LanguageFileInfo) TranslationBaseName added in v0.38.1

func (fi *LanguageFileInfo) TranslationBaseName() string

TranslationBaseName returns the base filename without any extension or language identificator.

type LanguageFs added in v0.38.1

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

func NewLanguageFs added in v0.38.1

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

func (*LanguageFs) Lang added in v0.38.1

func (fs *LanguageFs) Lang() string

func (*LanguageFs) LstatIfPossible added in v0.38.1

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

func (*LanguageFs) Open added in v0.38.1

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

func (*LanguageFs) Stat added in v0.38.1

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL