package resources

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

Package resources contains Resource related types.

Index

Functions

func CloneWithMetadataFromMapIfNeeded

func CloneWithMetadataFromMapIfNeeded(m []map[string]any, r resource.Resource) resource.Resource

CloneWithMetadataFromMapIfNeeded clones the given resource with the given metadata if the resource supports it.

func Copy

func Copy(r resource.Resource, targetPath string) resource.Resource

Copy copies r to the targetPath given.

func InternalResourceSourcePath

func InternalResourceSourcePath(r resource.Resource) string

InternalResourceSourcePathBestEffort is used internally to get the source path for a Resource. It returns an empty string if the source path is not available.

func InternalResourceSourcePathBestEffort

func InternalResourceSourcePathBestEffort(r resource.Resource) string

InternalResourceSourcePathBestEffort is used internally to get the source path for a Resource. Used for error messages etc. It will fall back to the target path if the source path is not available.

func InternalResourceTargetPath

func InternalResourceTargetPath(r resource.Resource) string

InternalResourceTargetPath is used internally to get the target path for a Resource.

Types

type AtomicStaler

type AtomicStaler struct {
	// contains filtered or unexported fields
}

func (*AtomicStaler) MarkStale

func (s *AtomicStaler) MarkStale()

func (*AtomicStaler) StaleVersion

func (s *AtomicStaler) StaleVersion() uint32

type GenericResourceTestInfo

type GenericResourceTestInfo struct {
	Paths internal.ResourcePaths
}

For internal use.

func GetTestInfoForResource

func GetTestInfoForResource(r resource.Resource) GenericResourceTestInfo

For internal use.

type ImageCache

type ImageCache struct {
	// contains filtered or unexported fields
}

ImageCache is a cache for image resources. The backing caches are shared between all sites.

type PostBuildAssets

type PostBuildAssets struct {
	PostProcessResources map[string]postpub.PostPublishedResource
	JSConfigBuilder      *jsconfig.Builder
	// contains filtered or unexported fields
}

type ResourceCache

type ResourceCache struct {
	sync.RWMutex

	CacheResourceRemote *dynacache.Partition[string, resource.Resource]
	// contains filtered or unexported fields
}

func (*ResourceCache) Get

func (*ResourceCache) GetOrCreate

func (c *ResourceCache) GetOrCreate(key string, f func() (resource.Resource, error)) (resource.Resource, error)

func (*ResourceCache) GetOrCreateFile

func (c *ResourceCache) GetOrCreateFile(key string, f func() (resource.Resource, error)) (resource.Resource, error)

func (*ResourceCache) GetOrCreateResources

func (c *ResourceCache) GetOrCreateResources(key string, f func() (resource.Resources, error)) (resource.Resources, error)

type ResourceSourceDescriptor

type ResourceSourceDescriptor struct {
	// The source content.
	OpenReadSeekCloser hugio.OpenReadSeekCloser

	// The canonical source path.
	Path *paths.Path

	// The normalized name of the resource.
	NameNormalized string

	// The name of the resource as it was read from the source.
	NameOriginal string

	// The title of the resource.
	Title string

	// Any base paths prepended to the target path. This will also typically be the
	// language code, but setting it here means that it should not have any effect on
	// the permalink.
	// This may be several values. In multihost mode we may publish the same resources to
	// multiple targets.
	TargetBasePaths []string

	TargetPath           string
	BasePathRelPermalink string
	BasePathTargetPath   string
	SourceFilenameOrPath string // Used for error logging.

	// The Data to associate with this resource.
	Data map[string]any

	// The Params to associate with this resource.
	Params maps.Params

	// Delay publishing until either Permalink or RelPermalink is called. Maybe never.
	LazyPublish bool

	// Set when its known up front, else it's resolved from the target filename.
	MediaType media.Type

	// Used to track dependencies (e.g. imports). May be nil if that's of no concern.
	DependencyManager identity.Manager

	// A shared identity for this resource and all its clones.
	// If this is not set, an Identity is created.
	GroupIdentity identity.Identity
}

type ResourceTransformation

type ResourceTransformation interface {
	Key() internal.ResourceTransformationKey
	Transform(ctx *ResourceTransformationCtx) error
}

ResourceTransformation is the interface that a resource transformation step needs to implement.

func NewFeatureNotAvailableTransformer

func NewFeatureNotAvailableTransformer(key string, elements ...any) ResourceTransformation

type ResourceTransformationCtx

type ResourceTransformationCtx struct {
	// The context that started the transformation.
	Ctx context.Context

	// The dependency manager to use for dependency tracking.
	DependencyManager identity.Manager

	// The content to transform.
	From io.Reader

	// The target of content transformation.
	// The current implementation requires that r is written to w
	// even if no transformation is performed.
	To io.Writer

	// This is the relative path to the original source. Unix styled slashes.
	SourcePath string

	// This is the relative target path to the resource. Unix styled slashes.
	InPath string

	// The relative target path to the transformed resource. Unix styled slashes.
	OutPath string

	// The input media type
	InMediaType media.Type

	// The media type of the transformed resource.
	OutMediaType media.Type

	// Data data can be set on the transformed Resource. Not that this need
	// to be simple types, as it needs to be serialized to JSON and back.
	Data map[string]any

	// This is used to publish additional artifacts, e.g. source maps.
	// We may improve this.
	OpenResourcePublisher func(relTargetPath string) (io.WriteCloser, error)
}

func (*ResourceTransformationCtx) AddOutPathIdentifier

func (ctx *ResourceTransformationCtx) AddOutPathIdentifier(identifier string)

AddOutPathIdentifier transforming InPath to OutPath adding an identifier, eg '.min' before any extension.

func (*ResourceTransformationCtx) PublishSourceMap

func (ctx *ResourceTransformationCtx) PublishSourceMap(content string) error

PublishSourceMap writes the content to the target folder of the main resource with the ".map" extension added.

func (*ResourceTransformationCtx) ReplaceOutPathExtension

func (ctx *ResourceTransformationCtx) ReplaceOutPathExtension(newExt string)

ReplaceOutPathExtension transforming InPath to OutPath replacing the file extension, e.g. ".scss"

type ResourceTransformer

type ResourceTransformer interface {
	resource.Resource
	Transformer
}

type Spec

type Spec struct {
	*helpers.PathSpec

	Logger       loggers.Logger
	ErrorSender  herrors.ErrorSender
	BuildClosers types.CloseAdder
	Rebuilder    identity.SignalRebuilder

	TextTemplates tpl.TemplateParseFinder

	Permalinks page.PermalinkExpander

	ImageCache *ImageCache

	ExecHelper *hexec.Exec

	*SpecCommon
	// contains filtered or unexported fields
}

func NewSpec

func NewSpec(
	s *helpers.PathSpec,
	common *SpecCommon,
	fileCaches filecache.Caches,
	memCache *dynacache.Cache,
	incr identity.Incrementer,
	logger loggers.Logger,
	errorHandler herrors.ErrorSender,
	execHelper *hexec.Exec,
	buildClosers types.CloseAdder,
	rebuilder identity.SignalRebuilder,
) (*Spec, error)

func (*Spec) BuildConfig

func (r *Spec) BuildConfig() config.BuildConfig

func (*Spec) MediaTypes

func (r *Spec) MediaTypes() media.Types

func (*Spec) NewResource

func (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, error)

NewResource creates a new Resource from the given ResourceSourceDescriptor.

func (*Spec) NewResourceWrapperFromResourceConfig

func (r *Spec) NewResourceWrapperFromResourceConfig(rc *pagemeta.ResourceConfig) (resource.Resource, error)

func (*Spec) OutputFormats

func (r *Spec) OutputFormats() output.Formats

func (*Spec) PostProcess

func (spec *Spec) PostProcess(r resource.Resource) (postpub.PostPublishedResource, error)

PostProcess wraps the given Resource for later processing.

func (*Spec) String

func (s *Spec) String() string

type SpecCommon

type SpecCommon struct {
	ResourceCache *ResourceCache
	FileCaches    filecache.Caches

	// Assets used after the build is done.
	// This is shared between all sites.
	*PostBuildAssets
	// contains filtered or unexported fields
}

The parts of Spec that's common for all sites.

type StaleValue

type StaleValue[V any] struct {
	// The value.
	Value V

	// StaleVersionFunc reports the current version of the value.
	// This always starts out at 0 and get incremented on staleness.
	StaleVersionFunc func() uint32
}

func (*StaleValue[V]) StaleVersion

func (s *StaleValue[V]) StaleVersion() uint32

type Transformer

type Transformer interface {
	Transform(...ResourceTransformation) (ResourceTransformer, error)
	TransformWithContext(context.Context, ...ResourceTransformation) (ResourceTransformer, error)
}

Source Files

docs.go image.go image_cache.go post_publish.go resource.go resource_cache.go resource_metadata.go resource_spec.go transform.go

Directories

PathSynopsis
resources/imagesPackage images provides template functions for manipulating images.
resources/images/exif
resources/images/imagetesting
resources/images/webp
resources/internal
resources/jsconfig
resources/kinds
resources/pagePackage page contains the core interfaces and types for the Page resource, a core component in Hugo.
resources/page/page_generate
resources/page/pagemeta
resources/page/siteidentities
resources/postpub
resources/resourcePackage resource contains Resource related types.
resources/resource_factories
resources/resource_factories/bundlerPackage bundler contains functions for concatenation etc.
resources/resource_factories/createPackage create contains functions for to create Resource objects.
resources/resource_transformers
resources/resource_transformers/babel
resources/resource_transformers/cssjsPackage cssjs provides resource transformations backed by some popular JS based frameworks.
resources/resource_transformers/htesting
resources/resource_transformers/integrity
resources/resource_transformers/js
resources/resource_transformers/minifier
resources/resource_transformers/templatesPackage templates contains functions for template processing of Resource objects.
resources/resource_transformers/tocss
resources/resource_transformers/tocss/dartsassPackage dartsass integrates with the Dart Sass Embedded protocol to transpile SCSS/SASS.
resources/resource_transformers/tocss/sass
resources/resource_transformers/tocss/scss
Version
v0.145.0 (latest)
Published
Feb 26, 2025
Platform
linux/amd64
Imports
53 packages
Last checked
3 hours ago

Tools for package owners.