valueobject

package
v0.0.0-...-85ec5f7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

Functions

func LstatIfPossible

func LstatIfPossible(fs afero.Fs, path string) (os.FileInfo, bool, error)

LstatIfPossible if the filesystem supports it, use Lstat, else use fs.Stat

func NewBasePathFs

func NewBasePathFs(source afero.Fs, path string) afero.Fs

NewBasePathFs creates a new BasePathFs.

func NewReadOnlyFs

func NewReadOnlyFs(source afero.Fs) afero.Fs

NewReadOnlyFs creates a new ReadOnlyFs.

func WrapFilesystem

func WrapFilesystem(container, content afero.Fs) afero.Fs

WrapFilesystem is typically used to wrap a afero.BasePathFs to allow access to the underlying filesystem if needed.

Types

type BaseFileDecoratorFs

type BaseFileDecoratorFs struct {
	afero.Fs
	Decorate func(fi os.FileInfo, filename string) (os.FileInfo, error)
}

func (*BaseFileDecoratorFs) LstatIfPossible

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

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 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 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)
}

func NewFileMeta

func NewFileMeta() *FileMeta

func (*FileMeta) Copy

func (f *FileMeta) Copy() *FileMeta

func (*FileMeta) JoinStat

func (f *FileMeta) JoinStat(name string) (FileMetaInfo, error)

func (*FileMeta) Merge

func (f *FileMeta) Merge(from *FileMeta)

func (*FileMeta) Open

func (f *FileMeta) Open() (afero.File, error)

type FileMetaInfo

type FileMetaInfo interface {
	os.FileInfo
	Meta() *FileMeta
}

func DecorateFileInfo

func DecorateFileInfo(fi os.FileInfo, metaFs afero.Fs, opener func() (afero.File, error),
	filename, filepath string, inMeta *FileMeta) FileMetaInfo

func NewFileMetaInfo

func NewFileMetaInfo(fi os.FileInfo, m *FileMeta) FileMetaInfo

type FilesystemsCollector

type FilesystemsCollector struct {
	SourceProject afero.Fs // Source for project folders

	OverlayMounts        *overlayfs.OverlayFs
	OverlayMountsContent *overlayfs.OverlayFs
	OverlayResources     *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 RootMapping

type RootMapping struct {
	// The virtual mount.
	From string
	// 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 GetRms

func GetRms(t *radixtree.Tree, key string) []RootMapping

func (RootMapping) Filename

func (r RootMapping) Filename(name string) string

type RootMappingFs

type RootMappingFs struct {
	afero.Fs
	RootMapToReal *radixtree.Tree
}

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

func (m *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible returns the os.FileInfo structure describing a given file.

func (*RootMappingFs) Open

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

Open opens the named file for reading.

func (*RootMappingFs) Stat

func (m *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 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

	// 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.

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.

type WalkFunc

type WalkFunc func(path string, info FileMetaInfo, err error) error

type Walkway

type Walkway struct {
	Fs   afero.Fs
	Root string

	WalkFn WalkFunc

	// We may traverse symbolic links and bite ourself.
	Seen map[string]bool

	Log loggers.Logger
	// contains filtered or unexported fields
}

func (*Walkway) Walk

func (w *Walkway) Walk() error

Jump to

Keyboard shortcuts

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