filesystems

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: Apache-2.0 Imports: 14 Imported by: 41

Documentation

Overview

Package filesystems provides the fine grained file systems used by Hugo. These are typically virtual filesystems that are composites of project and theme content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBaseFs

func WithBaseFs(b *BaseFs) func(*BaseFs) error

WithBaseFs allows reuse of some potentially expensive to create parts that remain the same across sites/languages.

Types

type BaseFs

type BaseFs struct {

	// SourceFilesystems contains the different source file systems.
	*SourceFilesystems

	// The project source.
	SourceFs afero.Fs

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

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.

func NewBase

func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) error) (*BaseFs, error)

NewBase builds the filesystems used by Hugo given the paths and options provided.NewBase

func (*BaseFs) AllDirs added in v0.56.0

func (fs *BaseFs) AllDirs() []hugofs.FileMetaInfo

func (*BaseFs) RelContentDir

func (b *BaseFs) RelContentDir(filename string) string

RelContentDir tries to create a path relative to the content root from the given filename. The return value is the path and language code.

func (*BaseFs) ResolveJSConfigFile added in v0.75.0

func (fs *BaseFs) ResolveJSConfigFile(name string) string

ResolveJSConfigFile resolves the JS-related config file to a absolute filename. One example of such would be postcss.config.js.

func (*BaseFs) WatchDirs added in v0.56.0

func (fs *BaseFs) WatchDirs() []hugofs.FileMetaInfo

TODO(bep) we can get regular files in here and that is fine, but we need to clean up the naming.

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 []hugofs.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) Contains

func (d *SourceFilesystem) Contains(filename string) bool

Contains returns whether the given filename is a member of the current filesystem.

func (*SourceFilesystem) MakePathRelative

func (d *SourceFilesystem) MakePathRelative(filename string) (string, bool)

MakePathRelative creates a relative path from the given filename.

func (*SourceFilesystem) Path added in v0.62.0

func (d *SourceFilesystem) Path(filename string) string

Path returns the mount relative path to the given filename if it is a member of of the current filesystem, an empty string if not.

func (*SourceFilesystem) RealDirs added in v0.45.1

func (d *SourceFilesystem) RealDirs(from string) []string

RealDirs gets a list of absolute paths to directories starting from the given path.

func (*SourceFilesystem) RealFilename added in v0.45.1

func (d *SourceFilesystem) RealFilename(rel string) string

type SourceFilesystems

type SourceFilesystems struct {
	Content    *SourceFilesystem
	Data       *SourceFilesystem
	I18n       *SourceFilesystem
	Layouts    *SourceFilesystem
	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 project folder.
	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 []hugofs.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.

func (SourceFilesystems) ContentStaticAssetFs added in v0.45.1

func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs

ContentStaticAssetFs will create a new composite filesystem from the content, static, and asset filesystems. The site language is needed to pick the correct static filesystem. The order is content, static and then assets. TODO(bep) check usage

func (*SourceFilesystems) FileSystems added in v0.62.0

func (s *SourceFilesystems) FileSystems() []*SourceFilesystem

FileSystems returns the FileSystems relevant for the change detection in server mode. Note: This does currently not return any static fs.

func (SourceFilesystems) IsAsset added in v0.45.1

func (s SourceFilesystems) IsAsset(filename string) bool

IsAsset returns true if the given filename is a member of the asset filesystem.

func (SourceFilesystems) IsContent added in v0.45.1

func (s SourceFilesystems) IsContent(filename string) bool

IsContent returns true if the given filename is a member of the content filesystem.

func (SourceFilesystems) IsData

func (s SourceFilesystems) IsData(filename string) bool

IsData returns true if the given filename is a member of the data filesystem.

func (SourceFilesystems) IsI18n

func (s SourceFilesystems) IsI18n(filename string) bool

IsI18n returns true if the given filename is a member of the i18n filesystem.

func (SourceFilesystems) IsLayout

func (s SourceFilesystems) IsLayout(filename string) bool

IsLayout returns true if the given filename is a member of the layouts filesystem.

func (SourceFilesystems) IsStatic

func (s SourceFilesystems) IsStatic(filename string) bool

IsStatic returns true if the given filename is a member of one of the static filesystems.

func (SourceFilesystems) MakeStaticPathRelative

func (s SourceFilesystems) MakeStaticPathRelative(filename string) string

MakeStaticPathRelative makes an absolute static filename into a relative one. It will return an empty string if the filename is not a member of a static filesystem.

func (SourceFilesystems) StatResource added in v0.45.1

func (s SourceFilesystems) StatResource(lang, filename string) (fi os.FileInfo, fs afero.Fs, err error)

StatResource looks for a resource in these filesystems in order: static, assets and finally content. If found in any of them, it returns FileInfo and the relevant filesystem. Any non os.IsNotExist error will be returned. An os.IsNotExist error wil be returned only if all filesystems return such an error. Note that if we only wanted to find the file, we could create a composite Afero fs, but we also need to know which filesystem root it lives in.

func (SourceFilesystems) StaticFs added in v0.45.1

func (s SourceFilesystems) StaticFs(lang string) afero.Fs

StaticFs returns the static filesystem for the given language. This can be a composite filesystem.

Jump to

Keyboard shortcuts

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