package deps

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

Index

Types

type BuildState

type BuildState struct {
	OnSignalRebuild func(ids ...identity.Identity)

	DeferredExecutions *DeferredExecutions

	// Deferred executions grouped by rendering context.
	DeferredExecutionsGroupedByRenderingContext map[tpl.RenderingContext]*DeferredExecutions
	// contains filtered or unexported fields
}

BuildState are state used during a build.

func (*BuildState) AddFilenameWithPostPrefix

func (b *BuildState) AddFilenameWithPostPrefix(filename string)

func (*BuildState) GetFilenamesWithPostPrefix

func (b *BuildState) GetFilenamesWithPostPrefix() []string

func (*BuildState) Incr

func (b *BuildState) Incr() int

func (*BuildState) SignalRebuild

func (b *BuildState) SignalRebuild(ids ...identity.Identity)

func (*BuildState) StartStageRender

func (b *BuildState) StartStageRender(stage tpl.RenderingContext)

StartStageRender will be called before a stage is rendered.

func (*BuildState) StopStageRender

func (b *BuildState) StopStageRender(stage tpl.RenderingContext)

StopStageRender will be called after a stage is rendered.

type Counters

type Counters struct {
	// Counter for the math.Counter function.
	MathCounter atomic.Uint64
}

Misc counters.

type DeferredExecutions

type DeferredExecutions struct {
	// A set of filenames in /public that
	// contains a post-processing prefix.
	FilenamesWithPostPrefix *maps.Cache[string, bool]

	// Maps a placeholder to a deferred execution.
	Executions *maps.Cache[string, *tpl.DeferredExecution]
}

type Deps

type Deps struct {
	// The logger to use.
	Log loggers.Logger `json:"-"`

	ExecHelper *hexec.Exec

	// The file systems to use.
	Fs *hugofs.Fs `json:"-"`

	// The PathSpec to use
	*helpers.PathSpec `json:"-"`

	// The ContentSpec to use
	*helpers.ContentSpec `json:"-"`

	// The SourceSpec to use
	SourceSpec *source.SourceSpec `json:"-"`

	// The Resource Spec to use
	ResourceSpec *resources.Spec

	// The configuration to use
	Conf config.AllProvider `json:"-"`

	// The memory cache to use.
	MemCache *dynacache.Cache

	// The translation func to use
	Translate func(ctx context.Context, translationID string, templateData any) string `json:"-"`

	// The site building.
	Site page.Site

	TemplateStore *tplimpl.TemplateStore

	// Used in tests
	OverloadedTemplateFuncs map[string]any

	TranslationProvider ResourceProvider

	Metrics metrics.Provider

	// BuildStartListeners will be notified before a build starts.
	BuildStartListeners *Listeners[any]

	// BuildEndListeners will be notified after a build finishes.
	BuildEndListeners *Listeners[any]

	// OnChangeListeners will be notified when something changes.
	OnChangeListeners *Listeners[identity.Identity]

	// Resources that gets closed when the build is done or the server shuts down.
	BuildClosers *types.Closers

	// This is common/global for all sites.
	BuildState *BuildState

	// Misc counters.
	Counters *Counters

	// Holds RPC dispatchers for Katex etc.
	// TODO(bep) rethink this re. a plugin setup, but this will have to do for now.
	WasmDispatchers *warpc.Dispatchers

	// The JS batcher client.
	JSBatcherClient js.BatcherClient
	// contains filtered or unexported fields
}

Deps holds dependencies used by many. There will be normally only one instance of deps in play at a given time, i.e. one per Site built.

func (Deps) Clone

func (d Deps) Clone(s page.Site, conf config.AllProvider) (*Deps, error)

func (*Deps) Close

func (d *Deps) Close() error

func (*Deps) Compile

func (d *Deps) Compile(prototype *Deps) error

TODO(bep) rework this to get it in line with how we manage templates.

func (*Deps) GetTemplateStore

func (d *Deps) GetTemplateStore() *tplimpl.TemplateStore

func (*Deps) Init

func (d *Deps) Init() error

func (Deps) MkdirTemp

func (d Deps) MkdirTemp(pattern string) (string, error)

MkdirTemp returns a temporary directory path that will be cleaned up on exit.

func (Deps) SendError

func (e Deps) SendError(err error)

SendError sends the error on a channel to be handled later. This can be used in situations where returning and aborting the current operation isn't practical.

func (Deps) StartErrorCollector

func (e Deps) StartErrorCollector() chan error

func (Deps) StopErrorCollector

func (e Deps) StopErrorCollector()

type DepsCfg

type DepsCfg struct {
	// The logger to use. Only set in some tests.
	// TODO(bep) get rid of this.
	TestLogger loggers.Logger

	// The logging level to use.
	LogLevel logg.Level

	// Logging output.
	StdErr io.Writer

	// The console output.
	StdOut io.Writer

	// The file systems to use
	Fs *hugofs.Fs

	// The Site in use
	Site page.Site

	Configs *allconfig.Configs

	// Template handling.
	TemplateProvider ResourceProvider

	// i18n handling.
	TranslationProvider ResourceProvider

	// ChangesFromBuild for changes passed back to the server/watch process.
	ChangesFromBuild chan []identity.Identity
}

DepsCfg contains configuration options that can be used to configure Hugo on a global level, i.e. logging etc. Nil values will be given default values.

type Listeners

type Listeners[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Listeners represents an event listener.

func (*Listeners[T]) Add

func (b *Listeners[T]) Add(f func(...T) bool)

Add adds a function to a Listeners instance.

func (*Listeners[T]) Notify

func (b *Listeners[T]) Notify(vs ...T)

Notify executes all listener functions.

type ResourceProvider

type ResourceProvider interface {
	NewResource(dst *Deps) error
	CloneResource(dst, src *Deps) error
}

ResourceProvider is used to create and refresh, and clone resources needed.

Source Files

deps.go

Version
v0.146.3
Published
Apr 12, 2025
Platform
js/wasm
Imports
33 packages
Last checked
1 minute ago

Tools for package owners.