package filesystems

import "github.com/gohugoio/hugo/hugolib/filesystems"

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

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 {
	// TODO(bep) make this go away
	AbsContentDirs []types.KeyValueStr

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

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

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

	// TODO(bep) improve the "theme interaction"
	AbsThemeDirs []string
	// 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, options ...func(*BaseFs) error) (*BaseFs, error)

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

func (*BaseFs) IsContent

func (b *BaseFs) IsContent(filename string) bool

IsContent returns whether the given filename is in the content filesystem.

func (*BaseFs) RelContentDir

func (b *BaseFs) RelContentDir(filename string) (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.

type SourceFilesystem

type SourceFilesystem struct {
	Fs afero.Fs

	Dirnames []string

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

MakePathRelative creates a relative path from the given filename. It will return an empty string if the filename is not a member of this filesystem.

type SourceFilesystems

type SourceFilesystems struct {
	Data       *SourceFilesystem
	I18n       *SourceFilesystem
	Layouts    *SourceFilesystem
	Archetypes *SourceFilesystem

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

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

Source Files

basefs.go

Version
v0.42.2
Published
Jun 28, 2018
Platform
js/wasm
Imports
12 packages
Last checked
1 hour ago

Tools for package owners.